Interactive chapter · Pattern map · Read after chapter 1, come back any time

The pattern map: every problem, and the pattern that fixes it

Each microservice pattern fixes one problem and hands you the next. Start from FTGO’s monolith, fix its problems one pattern at a time, and watch the new problems each fix creates.

open problemtrade-off to acceptpattern appliedfast fail / compensation

Why patterns come in chains

A pattern is a reusable answer to a problem in a context. The useful part is what happens after you apply it. Every pattern has a resulting context: benefits, costs, and new problems that need patterns of their own.

One chain through the pattern languageMicroservices create the shared database problem. Database per service fixes it but removes ACID across services. Saga fixes that but needs save-and-publish to be atomic. Transactional outbox fixes that but needs a relay, which transaction log tailing provides. Microservicesthe first pattern services share tables DB per servicefixes it no ACID across services Sagafixes it save + publish at once? Outboxfixes it who sends the rows? Log tailingfixes it
Read left to right: each fix (teal) creates the next problem (coral). The game below lets you walk every chain like this one.
Source: pattern names, groups and page numbers follow Chris Richardson’s Microservices Patterns (Manning, 2018). The explanations, story steps and labs on this page are written for this course.

Game: fix FTGO, one pattern at a time

FTGO (Food To Go) runs one large monolith. Each card below is a real problem: pick the pattern that fixes it. Some choices are traps that solve a different problem, and the card says why. Some problems have no pattern at all: they are trade-offs you accept and design around.

Problems in, patterns out

Fixed problems move to the log, along with the new problems each pattern caused. Click any pattern name in the log for its full card.

0open problems
0problems handled
0patterns used
0wrong picks

What happened

All 45 patterns, by the problem they solve

The same patterns, grouped the way the book groups them. Green ones are those you used in the game. Click a pattern to see its problem, solution and cost, and the chain around it: what made it necessary, and what it leads to.

The pattern language

Type a symptom (“slow”, “twice”, “who is the user”) or a pattern name to filter.


Lab: a hung service, without and with a circuit breaker

Order Service calls Payment Service synchronously. Order has a pool of 10 request threads and waits up to 30 seconds for each reply. Send 20 orders and watch the pool.

Partial failure

The problem is not that Payment is down. It is that Order goes down with it.

Payment
Circuit breaker
Breaker: CLOSED
paidthread stuck waitingrejected: no free threadsfailed fast, fallback used
Order threads busy0 / 10

Press “Send 20 orders”.

Lab: a crash between saving and publishing

Order Service must save the order and tell Kitchen about it. The database and the broker cannot share one transaction. Pick a failure and see what survives.

The dual-write problem

The fix is to stop writing to two places: write only to the database, and let a relay move the message.

Approach
What goes wrong

    Lab: a failed step, without and with a saga

    Creating an order touches four services, each with its own database. Pick the step that fails.

    Create Order across four databases

    A saga does not prevent failure. It makes sure every step that already changed data is undone by a compensating step.

    Approach
    Fails at

      Quick check: name the pattern

      Symptom → pattern

      8 questions. Pick one answer each.

        Recap

        Microservice patterns: common questions

        Which microservice pattern solves distributed transactions?

        The saga pattern: a sequence of local transactions, one per service, with compensating transactions that undo earlier steps when a later one fails.

        How do you publish an event reliably when you update a database?

        Use the transactional outbox: insert the message into an outbox table in the same transaction, then relay it to the broker by polling or transaction log tailing.