We will design the system with following requirement and design choice. We will use Spring Boot, Redis, Apache Kafka, MySQL.
- User Service - We will create a user who will use our payment service.
- Wallet Service - For each user we will create a wallet, through wallet user can send and receive money.
- Transaction Service - When user transfer money to different user Wallet should be updated for successful transaction.
- Notification Service - Send notification for wallet update, transaction update.
We will use Apache Kafka messaging for communicating between different service.
- When User is created we will produce message on "USER_CREATE" topic on kafka cluster.
- We will configure Wallet Service to listen( consume) on "USER_CREATE" topic, so whenever user is created, wallet service will get message from topic and create a new wallet, after wallet is created Wallet Service will produce message on "WALLET_CREATE" topic.
- We will configure Notification Service to listen on "WALLET_CREATE" topic, so whenever wallet is created for user, email service will send email to user.
- Transaction Service will create a transaction when user wants to transfer amount to other user. Transaction service will produce message on "TRANSACTION_CREATE" topic.
- We will configure Wallet Service to listen on "TRANSACTION_CREATE" topic, so whenever user make any transaction, wallet service will get message from topic and wallet service will process transaction, validate transaction and update transaction status.
- After processing transaction Wallet Service will produce message on "WALLET_UPDATE" topic. We will configure Notification Service to listen on "WALLET_UPDATE" topic, so whenever wallet is updated for user, notification service will send email to user with updated balance.
- After processing transaction, Wallet Service will produce message on "TRANSACTION_COMPLETE" topic with updated transaction status, We will configure Notification Service to listen on "TRANSACTION_COMPLETE" topic, so whenever transaction is updated for user, notification service will send email to user with transaction status.
- We will also configure Redis for caching
- Install redis - brew install redis
- Install kafka - brew install kafka
- Start Zookeeper - Go to [KAFKA_INSTALL_DIR] and run sh /bin/zookeeper-server-start.sh config/zookeeper.properties
- Start Kafka server - Go to [KAFKA_INSTALL_DIR] and run sh bin/kafka-server-start.sh config/server.properties
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic "USER_CREATE"