System-Design-Notes

[System Design] Digital Wallet

Distributed transaction

Untitled

the lock can be held for a long time; the coordinator can be a single point of failure.

Untitled

1 Reserve resources. 2 The coordinator collects replies, if all yes, do try-confirm; else do try-cancel.

Phase status table

Untitled

The service maybe restarts in the middle of TC/C. Need to store the progress of a TC/C in a transactional database.

Saga

Untitled

1 Each operation is an independent transaction on its own DB. 2 When one operation is finished, the next operation is triggered. 3 If one failed, roll back from the current to the first in reverse.

Saga executes linearly, TC/C could in parallel.

Event sourcing

Untitled

State machine: 1 validate commands and generate events; 2 apply the event to update the state

Command-query responsibility segregation (CQRS)

Untitled

CRQS: Rather than publishing the state, event sourcing publishes all the events. The external world could rebuild the state by itself.

Independent scaling; Optimized data scheme…

File-based command and event list

Untitled

Append-only data structure; cache recent commands and events in memory; use mmap to write to a local disk and cache recent content in memory at the same time.

Untitled