This application is created for managing financial accounts in payments solutions.
Available operations:
- Opening accounts (creating new accounts for customers)
- Listing accounts
- Get an account by id
- Freeze an account
- Delete an account
- Get balance from account
The application also handles financial transactions in async and concurrent manner for:
- Depositing amount to account
- Withdrawing amount from account
- Transferring amount between accounts
- Programming language:
go 1.16 - Message broker:
RabbitMQ - Database:
PostgreSQL - Cache:
Redis - Containerisation:
Docker - Container orchestrator:
Kubernetes,minikube - Service mesh:
Linkerd - Integration test and local development setup:
docker-compose
Customers, accounts and transactions are stored in the database. REST API is created and publicly exposed for CRUD operations with stored records.
The message broker is responsible for routing incoming deposit, withdraw and transfer messages, which will be consumed by the application from their dedicated queues. The balance will be updated in the database and in the cache. Database transactions are enabled on different isolation levels, in case of an error the transaction will be rolled back and (if applicable) retried.
If a transaction is successful an audit record will be saved to the database, and an event will be sent to the corresponding topic for notifying the customer also asynchronously.
-
The project uses
go, therefore you must install it first on your local machine if you want to develop the application. Also installDockerif you don't have it locally. -
If you want to run the application locally simply execute
make upin the project root folder. Docker-compose will start the database, message broker, cache containers. -
If you want to run the application from your IDEA then use port 8080 and set these environment variables:
DB_USER=myuserDB_NAME=mydbDB_PASSWORD=mypasswordMQ_USER=guestMQ_PASSWORD=guestMQ_HOST=localhostCACHE_HOST=localhostCACHE_PASSWORD=securepassDB_HOST=localhost
-
You can reach the API via the following endpoints:
- GET
/accounts/{id}- get an account - GET
/accounts- get stored accounts - GET
/accounts/{id}/balance- get balance from an account from the cache or database - POST
/accounts- create new account - PUT
/accounts/{id}/freeze- freeze an account - DELETE
/accounts/{id}- delete account
- GET
-
You can check the published messages on management console via
http://localhost:15672/. -
You can reach the
database on port 5432.Cacheis reachable on port6379. -
If you want to build a Docker image execute
make tag(and optionallymake push).
-
This application and the underlying infrastructure deployed to a Kubernetes cluster. Install
minikubeif you don't have it locally. -
Kubernetes descriptor YAML files can be found in
deployandkubernetesfolders. -
If you want to deploy, then follow these steps:
minikube start --memory=6g —cpus=2(start k8s cluster)make add-host(DNS entry for ingress)make kube-infra-up(this will apply infra descriptors)make kube-api-up(this will apply API descriptors)minikube service payments-api --url -n payments(public IP assigning)
-
Note this issue if you encounter problems in volume mounting for database container starts: minikube#4634
-
Optionally execute
minikube tunnelif you want to check the management console for the message broker.
-
If you want to mesh the services use
make mesh. This command will install Linkerd and its extensions (Jaeger and viz) and then inject the sidecar proxy containers. -
You can view the dashboard by executing
linkerd viz dashboard &.
-
Unit and integration tests are implemented as part of the project.
-
To run them execute
make test. This will create the test Docker containers and run the integration tests against them.