Atomic operations

An atomic operation can be defined as n+ different processes that all must succeed OR fail to ensure consistency.

graph TD
A --> B
B --> C

If A, B and C are all components of the same transaction (be it in the same or multiple services), any component before a failing one needs to revert their changes to reflect that the operation has failed.

Orchestration vs Choreography

Orchestration refers to the pattern of having a central component that ensures that other components are called and return a valid response in the correct order.

This is the main mode of operation when using RDA (Request Driven Architecture) but can also be adopted in EDA (Event Driven Architecture) through a command pattern which can allow for strict order of operations in combination with decoupling.

Choreography refers to the pattern of different components seamlessly working together without a real structure. One of the most common examples of EDA

Event Driven Architecture

eda

  • Difference between events (event, something happens, ) and commands (message, order, expects response, “confirm order”).

  • Notifications vs Containing data

  • Immutable

Producer Broker Consumer

Pros? Decoupling, scale, inversion of dependencies ( consumer needs to know about producer sending events )

Cons? Performance, Consistency (time), Complexity (What happens where?)

When? Scalability more important than performance, data replication necessary, parallel processing

Event Sourcing

The act of storing immutable logs of events that has happened that then act as persistence which services build their states from.

CQRS

cqrs

Command-Query Responsibility Segregation

Pattern for handling imbalance between read and write operations which also allows for the read and write operations to be done in different ways compared to a classic CRUD operation towards an SQL database.

Different services/systems can have built their state through event sourcing and those services are then in turn queried by by an overview/abstraction service over an HTTP API.

graph TD
  subgraph Command Side
    C1(Command Handler) -->|Sends Commands| S(Command Bus)
    S -->|Sends Commands| A(Aggregate)
    A -->|Emits Events| E(Event Store)
  end

  subgraph Query Side
    Q(Query Handler) -->|Sends Queries| R(Read Model)
  end

  subgraph Event Side
    E -->|Publishes Events| B(Event Bus)
    B -->|Updates Read Models| R
  end

https://www.youtube.com/watch?v=STKCRSUsyP0&pp=ygUudGhlIG1hbnkgbWVhbmluZ3Mgb2YgZXZlbnQgZHJpdmVuIGFyY2hpdGVjdHVyZQ%3D%3D