https://mermaidjs.github.io/mermaid-live-editor
sequenceDiagram
activate Frontend
Balancer->>Frontend: Request
Frontend->>Requests Queue: Request
Note over Frontend: Each request can have its own queue
Requests Queue-->>Request Handler: Request
activate Request Handler
Request Handler->>States Db: Changed Object States
Request Handler->>States Db: Transaction State
Request Handler->> Transaction Log: Transaction
Request Handler->>Responses Queue: Response
deactivate Request Handler
Responses Queue-->> Frontend: Response
Frontend->>Balancer: Response
deactivate Frontend
- Each
Frotnend
has its ownResponse Queue
- Request
- Modification operation, JSON
- Sync, Binary package Avro
- View, JSON
- Upload big data attachment
- Download big data
Balance incoming traffic to frontends
Service which uses a tool like traefik
or nginx
Save the request to a queue
- Use request fields to find a queue
Keep requests
- Request is deleted after it is processed
Handle requests using eventual atomicity
approach
- Check and reject Requests (say no permissions to perfom given operation)
- Update object states
- Feed
Transaction Log
Persistency to provide eventual atomicity
- Each request can modify one or few states
- Eventually all modifications must be either applied or compensated
Design details:
- Each state has a key
- State is a
dedicated
(выделенное �о�то�ние
) if only one transaction can own the state - State is
shared
(раздел�емое �о�то�ние
) if few transactions can be applied. Shared states must keep list of all applied transactions
Example: customer must have unique email
- Two states are needed to handle this requirement
Customer Email
is a dedicated state, has anemail
as a key andCustomer.id
as a valueCustomer Data
is a shared state, hascustomer.id
as a key and customer fields as a valueCreate Customer
reqest first try to createCustomer Email
state, if ok,Customer Data
is createdUpdate Customer
request first try to createCustomer Email
state for a new email value, then updateCustomer Data
state and finally deactivate previousCustomer Email
Purpose:
- Keep processed transactions (both, "commited" and "rejected")
- Effective rescan of processed transactions
Requests Queue
, States Db
and Transaction Log
can be implemented as a single database table for the price of perfomace and scalability.
- Sync logs
- ??? Request id - can we use client on or always use internal id (say, queue offset)
- Serivce call (Send email)
Java for microservices
- https://codeburst.io/microservices-in-java-never-a7f3a2540dbb
- https://buoyant.io/2016/06/17/small-memory-jvm-techniques-for-microservice-sidecars/
- We found two specific techniques to be the most beneficial: turning off one of the two JIT compilers enabled by default (the “C2” compiler), and using a 32-bit, rather than a 64-bit, JVM.
Nakadi
- https://github.com/zalando/nakadi
- Validates schemas - no
Exactly once
-
https://dzone.com/articles/kafka-clients-at-most-once-at-least-once-exactly-o
-
https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/
-
Binding keys, routing keys https://habrahabr.ru/post/201096/
-
Architecture description https://technet.microsoft.com/en-us/library/bb124225(v=exchg.65).aspx
a->b
+--------+ +-------+ +-------+
| | --+ ditaa +--> | |
| Text | +-------+ |diagram|
|Document| |!magic!| | |
| {d}| | | | |
+---+----+ +-------+ +-------+
: ^
| Lots of work |
+-------------------------+