Skip to content

afshin-deriv/event-driven-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comic by Forrest Brazeal

Event-Driven Microservices Backend Case study

Proof of Concept for a scalable simple trading Application, based on simplified event-driven microservices architecture and Docker containers. 🐳

MIT license

forthebadge forthebadge

  • 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.

Requirements:

  • docker >= 17.12.0+
  • docker-compose

Running the entire application stack

  • 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

Environments

The Compose file contains the following environment variables:

  • POSTGRES_USER the default value is postgres
  • POSTGRES_PASSWORD the default value is changeme
  • PGADMIN_PORT the default value is 5432

How-To

$ 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"}

Payment Service

Read request from payment stream channel, and response in payment-response channel

Create user

request
{
  "id": "message identifier",
  "type": "ADD_USER"
}

response
{
  "id": "request message identifier",
  "status": "OK/ERROR",
  "user_id": "New user identifier",
  "message": "descriptive message",
}

Remove user

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",
}

Deposit

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",
}

Withdraw

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"
}

User info

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"
}

Trade Service

Read request from api stream channel, and response in api-response channel

Purchase

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"
}

Sell

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"
}

About

Simple Event-Driven Microservice application with Node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •