This project is a microservices-based financial system where all client requests are routed through an API Gateway. It includes authentication, user management, account handling, payments, and fund transfers. The system leverages event-driven communication with Kafka and Avro-based schema registry.
Normally jwt secrets needs to be in the keystore, but I am not adding it with this release because I want to stay away from questions like "where did this come from or where is this keystore? There is one more thing I need to clarify: you will see some code repeats between services. Most of it can be collected in a shared library, but I didn't add a shared library because I don't want to bother explaining "unseen code", and if anyone tries to work on these project, they can configure keystores themselves.
The system consists of the following services:
-
API Gateway: Routes all incoming requests and handles JWT authentication.
-
Eureka Service Registry: Manages service discovery.
-
Authentication Service: Handles user registration, login, and JWT token management.
-
User Service: Stores user details and publishes user registration events.
-
Account Service: Manages user accounts, balance, and account status.
-
Payment Service: Processes payments and synchronizes account data.
-
Fund Transfer Service: Handles fund transfers and ensures transaction consistency.
All services use Kafka to produce and consume events as Avro records. The system follows the Outbox Pattern, where events are stored in an outbox table before being published.
-
A service writes an event to the outbox table with a
PENDINGstatus. -
The Event Service periodically scans for pending events.
-
Events are published to Kafka and marked as
PUBLISHED. -
If event processing fails, the consumer republishes the event as
FAILED.
-
JWT Handling: Tokens are stored in HttpOnly cookies.
-
Gateway Validation: The API Gateway validates JWT tokens using shared keystores.
-
User Registration
-
The user registers via the API Gateway.
-
The Authentication Service stores credentials and creates a JWT.
-
The User Service persists user details and emits a
UserRegisteredevent. -
The Account Service and Payment Service consume this event to initialize user accounts.
-
-
Fund Transfer
-
The Payment Service initiates a transaction and builds a
PaymentCreatedevent. -
The Fund Transfer Service consumes this event and decides if the payment is valid.
-
If valid, it emits a
PaymentProcessedevent. -
The Account Service updates balances accordingly.
-
-
Spring Boot (Microservices framework)
-
Kafka (Event streaming)
-
PostgreSQL & MongoDB (Databases)
-
Avro (Schema registry for events)
-
Docker (Containerization)
-
JWT (Authentication)
-
API Gateway (Routing & authentication)
-
Implement Dead Letter Queue (DLQ) for handling failed events.
-
Implement scheduled sync for Account Sync Service.
-
Introduce rollback mechanisms for failed fund transfers.
To run the project, ensure you have Docker installed and execute:
# Start all services using Docker Compose
docker-compose up -dFor local development, run services individually via Maven:
mvn spring-boot:run