Skip to content

Architecture patterns: recap and quiz

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
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

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.

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. Can you run it? Provisioning, monitoring, tracing, fast deployment and on-call, for each service you add. (Microservices)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)
  12. 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)

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.
  1. Line 1 of 10Placing an order must update the stock, the order and the payment record so that all three happen or none does.
  2. Line 2 of 10A product page must be built from data of six parts of the domain and returned in under 50 ms.
  3. Line 3 of 10Five teams keep breaking each other's code in one codebase, but there is one weekly release and the team has only basic monitoring.
  4. Line 4 of 10The search part needs twenty times the instances of the rest, and its team deploys ten times a day without waiting for anyone.
  5. Line 5 of 10One team's weekly release is blocked by another team's broken change in the shared release, and both teams already have automated delivery, tracing and on-call.
  6. Line 6 of 10When an order is placed, invoicing, email and analytics must each react, more reactions will be added later, and the order service must not wait for them.
  7. Line 7 of 10A part that is down for an hour must catch up afterwards instead of making the sender fail.
  8. Line 8 of 10The orders screen is read 2,000 times a second and written 20 times a second, and its query joins five normalised tables.
  9. Line 9 of 10A dashboard needs a denormalised view of data that a complex write model validates, and a few seconds of delay is acceptable.
  10. Line 10 of 10A forecasting job must re-read what happened yesterday and today at its own pace, without slowing the services that produced it.

Check your answers at least once before looking at the answers.

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

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.

Question 1 of 10

Five teams work in one codebase. Releases are weekly, one database transaction covers an order, and monitoring is basic. Teams keep editing each other's tables.

Which change fits best first?

Choose one answer.

Question 2 of 10

A request goes through eight services in a row. Each is available 99.95% of the time, and they fail independently.

What availability does a request that waits on all eight have?

Enter a number and choose its unit.

percent
Question 3 of 10

Which of these is an event?

Choose one answer.

Question 4 of 10

A consumer reads OrderCancelled for order 42 before OrderPaid for the same order, and the order ends up shown as paid.

What fixes it?

Choose one answer.

Question 5 of 10

A consumer adds the amount of each OrderPlaced event to the day's revenue. After a rebalance, one event is delivered twice.

What should the consumer do?

Choose one answer.

Question 6 of 10

An orders screen is read 2,000 times a second and written 20 times a second. Its query joins five normalised tables.

Which is the strongest reason to use CQRS here?

Choose one answer.

Question 7 of 10

A bank has 1,000,000 accounts. Each account records 20 events a day, and an event takes 200 bytes.

How large is the event log after one year, in terabytes?

Enter a number and choose its unit.

Question 8 of 10

A team says: "We use event sourcing, so we are doing CQRS."

Is the claim right?

Choose one answer.

Question 9 of 10

Which of these belong at the gateway?

Choose every answer that applies.

Question 10 of 10

A team with a manual two-day release process and no distributed tracing wants to start with 30 microservices.

What do you advise?

Choose one answer.

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.