Comic by Forrest Brazeal
Proof of Concept for a scalable simple trading Application, based on simplified event-driven microservices architecture and Docker containers. 🐳
- Trade service: handles buy and sell transactions and publishes respective events
- Payment service: manages the funds (deposits and withdrawals) for the users and published respective events
- Reporting service: listens to the events from both Trade and Payment services and shows statistics.
- docker >= 17.12.0+
- docker-compose
- Clone or download this repository
- Go inside of directory,
cd Case-study-Event-driven-architecture
docker-compose up -d --build
docker-compose down --rmi all
The Compose file contains the following environment variables:
POSTGRES_USER
the default value is postgresPOSTGRES_PASSWORD
the default value is changemePGADMIN_PORT
the default value is 5432
$ npm install -g wscat
$ wscat -c 127.0.0.1:3000
> {"type": "add_user"}
< {"status":"OK","response":"User with id b1032345-b16e-4a47-879a-5186009d8d6c has been created"}
> {"type": "deposit", "user_id": "b1032345-b16e-4a47-879a-5186009d8d6c", "amount": 150}
< {"status":"OK","response":"Deposit to account b1032345-b16e-4a47-879a-5186009d8d6c with amount of 150 has been done"}
> {"type": "user_info", "user_id": "b1032345-b16e-4a47-879a-5186009d8d6c"}
< {"status":"OK","response":"user_id: b1032345-b16e-4a47-879a-5186009d8d6c, balance: $150.00, created_at: 2023-01-18 04:31"}
Read request from payment stream channel, and response in payment-response channel
request
{
"id": "message identifier",
"type": "ADD_USER"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"user_id": "New user identifier",
"message": "descriptive message",
}
request
{
"id": "message identifier",
"type": "REMOVE_USER",
"user_id": "user identifier"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"user_id": "deleted user identifier",
"message": "descriptive message",
}
request
{
"id": "message identifier",
"type": "DEPOSIT",
"user_id": "user identifier",
"amount": "amount to add to user account"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"message": "descriptive message",
}
request
{
"id": "message identifier",
"type": "WITHDRAW",
"user_id": "user identifier",
"amount": "amount to remove from user account"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"message": "descriptive message"
}
request
{
"id": "message identifier",
"type": "USER_INFO",
"user_id": "user identifier"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"user_id": "user identifier",
"amount": "Amount in user account",
"message": "descriptive message"
}
Read request from api stream channel, and response in api-response channel
request
{
"id": "message identifier",
"type": "BUY",
"user_id": "user identifier",
"symbol": "Asset symbol",
"price": "price to buy",
"amount": "amount to buy"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"message": "descriptive message"
}
request
{
"id": "message identifier",
"type": "SELL",
"user_id": "user identifier",
"symbol": "Asset symbol",
"price": "price to sell",
"amount": "amount to sell"
}
response
{
"id": "request message identifier",
"status": "OK/ERROR",
"message": "descriptive message"
}