Architecture patterns: recap and quiz
The module in six sentences
Section titled “The module in six sentences”- Monolith and modular monolith. One deployable gives in-process calls and one transaction, and a modular monolith adds modules with a public interface and boundaries that a tool checks, but not independent release or scaling.
- Microservices. Independent deployment, scaling and team ownership are bought with network calls (five services at 99.9% in series are 99.5% available), split data with no cross-service transaction, and an operational load for each service.
- Event-driven architecture. Publishing a fact instead of calling each receiver takes the receivers off the request path, and costs an implicit flow, eventual consistency, partial order and duplicates.
- CQRS. A separate read model, shaped for the questions and scaled on its own, is paid for with a second model to keep in step and a read side that can lag.
- Event sourcing. Storing every change as an event gives a history and state that can be rebuilt, and costs a log that grows, events that are never edited and a format that must be kept readable.
- API gateway and BFF. A gateway gives clients one entry point and does cross-cutting jobs once, a backend for each client shapes the calls for it, and both are on every request path and must be sized and made redundant.
How each one breaks
Section titled “How each one breaks”| Idea | What breaks | What you see | What helps |
|---|---|---|---|
| Modular monolith | Boundaries nobody checks | A change in one module breaks another, with no interface changed | A boundary check in the build, own data for each module |
| Microservices | A chain of calls, a split transaction | Availability below that of any service, half-done orders | Timeouts, breakers, bulkheads, compensations |
| Event-driven | A slow, stuck or duplicated consumer | Stale data, a growing lag, an effect applied twice | An alert on lag, a limit on retries, idempotent consumers, an outbox |
| CQRS | A read side that lags | A new order missing from the list | Answer from the write, read the write side, wait for a version |
| Event sourcing | Wrong events, a changed format | Errors that cannot be edited out, old events nobody can read | Compensating events, upcasting, snapshots |
| Gateway and BFF | One component on every path | Everything down, or every route blocked by one slow service | Several instances, a timeout and a limit for each route |
A checklist for choosing a style
Section titled “A checklist for choosing a style”Use it to prepare for an interview or to review a design. The order matters: it starts with the problem, and the style comes last.
- What is the actual problem? Blurred boundaries between teams, a shared release that blocks, one part that needs far more capacity, or reads that outnumber writes. Name it before you name a style. (Monolith and modular monolith)
- How many teams are there, and how often do they block one another? A small team in one codebase has no problem that services solve. (Microservices)
- Must a rule hold across several parts at once? If it must, keep those parts in one transaction. Services and events do not give you one. (Monolith and modular monolith)
- Must a part be released or scaled on its own? That is what a separate deployable buys, and what a modular monolith does not give. (Microservices)
- Can you run it? Provisioning, monitoring, tracing, fast deployment and on-call, for each service you add. (Microservices)
- How many services does one request wait on, and which can fail without breaking it? Multiply the availabilities, and take the soft ones off the hard path. (Microservices)
- Who reacts to this, and does the sender need the answer? A fact for any number of readers is an event. An instruction to one is a command. (Event-driven architecture)
- What happens with order, duplicates and lag? Key by the entity, make consumers idempotent, publish through an outbox, and alert on lag. (Event-driven architecture)
- Do reads and writes differ in load and shape, and can the user live with a delay? If both, a read model may pay; if not, one model is better. (CQRS)
- Do you need the history, an audit trail or a rebuildable state? Then consider event sourcing for that part only, and plan snapshots, corrections and the format of events. (Event sourcing)
- What do the clients need at the edge? Routing and cross-cutting jobs in a gateway, a backend for each kind of client where their needs differ, and no business rules in either. (API gateway and BFF)
- What is the first step you can measure and undo, and what would make you change your mind? Extract one part, not rewrite the system. (Monolith and modular monolith)
Sort the situations
Section titled “Sort the situations”Ten situations. For each, ask what the situation needs: one transaction, independent release or scale, a reaction without waiting, or a read side shaped differently from the write side.
Challenge
Which style fits the problem?
Four of the module's ideas answer four different problems. A modular monolith gives boundaries and one transaction inside one deployable. Microservices give independent deployment and scaling, and cost the network and split data. Event-driven communication lets parts react to a fact without the sender waiting. CQRS gives a read model shaped for the reads. Put each situation under the idea that answers it.
Sorting needs JavaScript.
Categories
- Modular monolith
- One deployable and one database, with modules whose boundaries are enforced.
- Microservices
- Services that each own their data and are deployed and scaled on their own.
- Event-driven communication
- Publish a fact; any number of subscribers react later, on their own.
- CQRS
- A separate read model, shaped for the questions that are asked of it.
Check your answers at least once before looking at the answers.
Defend a choice
Section titled “Defend a choice”An interviewer rarely asks for a definition. They ask what you would do, and then they ask why not the other thing. Write your answer before you open the model answer, and score it against the rubric.
Interview question
Writing and reviewing an answer needs JavaScript.
The interviewer asks
Your company runs one monolith, built by 40 engineers in six teams. The last three releases were late because of a broken change from another team, and the CTO wants to rewrite it as microservices. What do you say?
Assume one PostgreSQL database, a pipeline of 45 minutes, basic monitoring and no distributed tracing, and about 3,000 requests a second at peak.
Write your answer first. The strong answer unlocks once you have written a real attempt.
0 of 80 characters written to unlock the strong answer
Check your understanding
Section titled “Check your understanding”Ten questions cover the whole module. Every option is explained, whether it is right or wrong.
Architecture patterns: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”The patterns here decide where the boundaries go. The next module, on distributed patterns, deals with what crosses them: a business process that spans several services and has no transaction to hold it together, and a message that must be published exactly when a change is saved. Ask of every boundary you draw what happens to a request that is half done when the boundary fails.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.