This document is a work in progress documenting architectural choices made for Velox shop.
Microservice in Velox shop
--------------------------
### Principles
1. Single purpose
Each service service should focus on single function and do it well.
2. Lose coupling
Direct strict dependencies between services should be avoided.
3. High cohesion
Each service should be standalone and self contained.
### Requirements
1. No shared databases.
2. Token based shared authentication.
<!-- ### Decoupling building service from running service
### Observability -->
Inter-service communication
--------------------------------
### Interaction approach
Different approaches for services communication can be applied. Most common ones were considered.
**We decided to apply the orchestration model with central integration point.**
#### Direct interaction
Service can communicate directly with any other service to fulfill own duty.
```mermaid
sequenceDiagram
Participant User
Participant Frontend
User ->>+Frontend : add item\n to cart
Frontend ->>+ Cart service : add item\n to cart
Cart service ->>+ Product service : request required\n product data
Product service -->>- Cart service : return product\n data
Cart service ->>+ Stock service : request stock data
Stock service -->>- Cart service : return stock data
Cart service -->>- Frontend : return operation\n result
Frontend -->>- User : display operation\n confirmation
```
Pros:
* easy approach
* SOA like implementation
Cons:
* High coupling and low cohesion
* API dependencies between services
* effectively distributed-monolithic application
#### Orchestration model with central integration point
Integration point(s) is responsible to gather and compose all resources for given workflow.
```mermaid
sequenceDiagram
Participant User
Participant Frontend
Participant integration as Integration <br /> Point
Note over Frontend, integration : Both can be <br/> single application
User ->>+Frontend : add item\n to cart
Frontend ->>+ integration : add item\n to cart
integration ->>+ Product service : request required\n product data
Product service -->>- integration : return product\n data
integration ->>+ Stock service : request stock data
Stock service -->>- integration : return stock data
integration ->>+ Cart service : add item to cart passing required product data
Cart service -->>- integration : return operation\n result
integration -->>- Frontend : return operation\n result
Frontend -->>- User : display operation\n confirmation
```
Pros:
* full decoupling of services
* ease of service change - only integration point potentially affected
* no service dependency allow integration of any service alone in new projects
Cons:
* potential performance bottleneck
* business logic may leak to workflow (integration point) leading to fat implementation
##### Service bus or workflow engine
Distinct functional aspects can be separated in different integration points, eg. checkout integration.
Workflows can be also implemented serverless, eg. as AWS Lambda functions.
##### Direct integration in client
Services can be accessed directly from client.
#### No inter-service interaction (event driven asynchronous replication)
All services must store data needed for their operation. Replication is based on change announcements published by data source service. Other services listen to those events and update their copies.
```mermaid
sequenceDiagram
Participant User as User / FE
Participant PIM
Participant ERP integration
Participant mb as Message bus
Participant cart as Cart service
Participant cartStore as Cart service <br /> persistence