Learnings

System design, part 6 of 12

Architecture Styles

An architecture style is a decision about where the boundaries go: what deploys together, who owns which data, and how the pieces talk. This page compares the main shapes, shows how to split a system and how the parts cooperate, covers the platform patterns an architect is expected to know, and ends with a way to choose and to defend the choice in an interview.

Shapes of a system

Part 1 of 5 · what deploys together

Four deployment shapes cover almost every system. They differ in how many things you deploy and who owns the data, not in how clean the code is. Code structure inside a deployable is a separate choice.

The four shapes compared

Shapes of a system

Default to the simplest shape that the team and the load allow. Each step to the right buys independent deployment or scaling and pays for it in operations and in distributed-systems problems.

MonolithModular monolithMicroservicesServerless functions
Team size it suits1 to about 10 engineersAbout 10 to 50, several teams in one repoMany teams (roughly 50+ engineers) that block each other on releasesAny size, for event-driven or spiky workloads
DeploymentOne artifact, one pipelineOne artifact, modules with enforced boundariesOne pipeline per service, independent releasesPer function, platform runs it
ScalingClone the whole app behind a load balancerSame; hot modules can be extracted laterEach service scales on its own curveAutomatic, per request, to zero when idle
Data ownershipOne shared schemaOne database, a schema per module, no cross-module joinsA database per serviceExternal managed stores; functions are stateless
Operational costLowestLowHigh: tracing, service discovery, per-service on-call, platform teamLow to run, pay per call; expensive at steady high volume
Calls between partsIn-process, nanoseconds, transactionalIn-process through module interfacesNetwork: about 0.5 to 2 ms each inside a data centre, can failNetwork plus events
Failure modesOne bug or memory leak takes everything down; slow builds; merge contentionSame blast radius as a monolith; boundaries erode without toolingPartial failure, cascading timeouts, inconsistent data, version skewCold starts (roughly 100 ms to seconds), time limits, connection exhaustion on databases, vendor lock-in

Senior signal: say which shape you start with and why, then name the measurable trigger that would move you to the next one. "Microservices" stated as a default with no trigger reads as mid-level.

The four shapes drawn

Shapes of a system

Monolith

Everything ships together and shares one schema. Scaling means more copies of the whole thing.

Modular monolith

Still one deployment, but each module owns its tables and is called only through its interface. This is a microservice split without the network.

Microservices

Each service deploys alone and owns its database. Every arrow between services is now a network call that can be slow or fail.

Serverless functions

Functions are stateless and triggered by requests or events. The platform owns scaling; you own the wiring between triggers.

When microservices are worth it

Shapes of a system

Microservices solve an organisational problem (many teams shipping independently) more often than a technical one. Split when at least one of these is true and measurable:

  • Release contention: teams wait on each other to deploy, or one team's bug rolls back everyone's release.
  • Divergent scaling: one component needs 50 times the capacity, or GPUs, or a different memory profile.
  • Divergent availability or compliance: payments needs 99.99% and PCI scope; the recommendations widget does not.
  • Fault isolation: a leak in report generation must not take down checkout.
  • Different technology: a component is genuinely better served by another runtime or data store.

Stay with a (modular) monolith when the domain is still being discovered, the team is small, or you cannot yet afford the platform: automated deployment, centralised logs, tracing and on-call per service.

The distributed monolith

The worst of both: separate deployables that still must be released, scaled or debugged together.

SymptomRoot cause
A feature needs coordinated deploys of 3+ servicesBoundaries cut through a business capability
Services read or write each other's tablesShared database
One service down makes most requests failLong synchronous call chains, no fallbacks
Shared library upgrade forces a fleet-wide releaseDomain logic in shared code instead of behind an API
Cannot run or test one service aloneNo contracts; integration only testable end to end

Interview tip: the test for a real service is "can it be deployed on a Tuesday afternoon without telling any other team?" If not, it is a module with a network cable through it.

Layered, hexagonal, clean

Shapes of a system

These describe structure inside one deployable and apply to a monolith or a single microservice alike. All three separate business rules from I/O; they differ in which way dependencies point.

In layered code the business logic depends on the database layer. In hexagonal and clean architecture the core defines interfaces (ports) and the infrastructure implements them, so the dependency on the database is inverted.
Layered (n-tier)Hexagonal (ports and adapters)Clean architecture
Dependency ruleEach layer calls the one belowAdapters depend on the core; the core depends on nothing externalSame rule, with named rings: entities, use cases, interface adapters, frameworks
Core knows the database?Yes, usually through an ORMNo, only an outbound portNo
Testing the rulesNeeds a database or heavy mockingSwap adapters for in-memory fakesSame
CostLeast code; fine for CRUDMore interfaces and mapping codeMost ceremony; several models to map between
Use whenThin logic over a databaseReal domain rules, several entry points or swappable infrastructureLarge, long-lived domain core with many use cases

Hexagonal and clean are the same idea at different levels of prescription. For the code-level mechanics (dependency inversion, repository, adapter) see Design Principles and Design Patterns, and Low-Level Design.

Splitting a system

Part 2 of 5 · where the boundaries go

A good boundary keeps changes local: most features touch one service, and most requests are served from data the service already owns. Boundaries follow the business domain and the data, not the technical layers.

Boundaries with domain-driven design

Splitting a system

Domain-driven design gives the vocabulary interviewers expect when you justify a service boundary.

TermDefinitionE-commerce example
Ubiquitous languageOne shared vocabulary used by the business and in the code, valid inside one context"Order", "shipment", "refund" mean exactly one thing to the team that owns them
Bounded contextThe boundary inside which a model and its language are consistent. The natural candidate for a service or module"Product" in Catalog has description and images; in Inventory it is a SKU with a count; in Shipping it is weight and dimensions
AggregateA cluster of objects changed together in one transaction through a root; the unit of consistency. Other aggregates are referenced by id onlyOrder with its order lines. Customer and Product are referenced by id
Domain eventA fact that already happened, named in the past tenseOrderPlaced, PaymentCaptured, StockReserved
Context mapThe relationships between contexts: who is upstream, who conforms, where translation happensOrdering is downstream of Catalog and upstream of Shipping
A context map for a shop. Arrows point from the caller or publisher (dashed for events); each box is a bounded context with its own model of "product" and "customer".
  • Finding contexts: look for where the same word changes meaning, where a different team or business process takes over, and where data changes at a different rate.
  • Aggregate rule: one transaction changes one aggregate. Anything across aggregates is eventually consistent (events, sagas). This is what makes a later split possible.
  • Size: a service is one bounded context or a few closely related aggregates, not one entity. "User service, order service, product service" by table is an entity split and tends to produce chatty calls.
  • Spend unevenly: build the core domain in-house, keep supporting contexts simple, buy generic ones.

Database per service

Splitting a system

A service owns its data and exposes it only through its API or its events. "Database" means a private schema at minimum; it does not have to be a separate server.

On top the schema is the real interface and nobody controls it. Below, the only ways in are an API and an event stream, both versioned.

Why a shared database couples services:

  • Schema coupling: a column rename needs every reader changed and deployed together.
  • Hidden contracts: other teams' queries depend on your tables, indexes and even row ordering.
  • Runtime coupling: one team's slow query or lock exhausts connections for everyone; one capacity limit and one failure domain.
  • No encapsulation: invariants enforced in service code are bypassed by direct writes.

Trade-off: you give up cross-service joins and ACID transactions. Joins become API composition or a local read copy; transactions become sagas (see Distributed Systems Patterns). If two "services" need a transaction together constantly, they are probably one service.

Ownership and duplication

Splitting a system

Every piece of data has exactly one system of record that may write it. Everyone else holds a read-only copy or asks the owner.

Need data from another serviceHowPay with
Rarely, must be freshSynchronous API call to the ownerLatency and availability coupling
Often, slightly stale is fineKeep a local replica fed by the owner's eventsEventual consistency, storage, rebuild logic
As it was at a point in timeCopy the value into your own record (snapshot)Nothing: this is correct, not denormalised. An order must keep the price and address at purchase time
For reporting across everythingStream all services into a warehouse or lakeA pipeline to operate; minutes to hours of lag
  • Duplicate data, never duplicate ownership. A copy carries the owner's id and version so it can be refreshed or reconciled.
  • Publish events reliably with the transactional outbox or change data capture, not a dual write (see Distributed Systems Patterns).
  • Plan for rebuilds: a consumer must be able to rebuild its copy from a replay or a bulk export.

Migrating off a monolith

Splitting a system

Never rewrite in one step. Put a routing layer in front, move one capability at a time, and keep the monolith serving the rest until nothing is left. This is the strangler fig pattern.

The facade moves traffic route by route and percentage by percentage. Each step is reversible by changing a routing rule.
  1. Insert the facade (gateway or reverse proxy) with all routes still pointing at the monolith.
  2. Pick a capability with clear boundaries and real pain. Build it as a service with its own data store.
  3. Migrate the data: backfill, then keep in sync (change data capture or dual write with reconciliation), compare results in shadow mode.
  4. Shift traffic gradually; keep the old path as the rollback.
  5. Delete the old code and tables. A migration that skips this step leaves two systems forever.
TechniqueWhat it isUse when
Strangler figRoute at the edge; new system grows around the old oneThe capability has its own entry points (URLs, topics)
Anti-corruption layerA translation layer so the new model is not shaped by the legacy model (or a vendor's)The new service must still call or be called by the old one
Branch by abstractionInside the codebase: introduce an interface, put old and new implementations behind it, switch with a flag, delete the oldThe thing being replaced is deep inside the monolith with no external entry point
Parallel runCall both, serve the old result, compare and log differencesCorrectness is critical (pricing, billing)

Failure mode: extracting the code but leaving the tables in the monolith database. The data migration is the hard half; say how you would do it.

Conway's law

Splitting a system

Systems end up mirroring the communication structure of the organisation that builds them, so a service boundary that cuts across a team, or a team that spans many services, will be fought constantly. The practical use is the "inverse Conway manoeuvre": decide the architecture you want, then shape teams to match it, one team owning each service end to end.

How services cooperate

Part 3 of 5 · commands, events and read models

Once there are several services, the main design question is who knows about whom. Synchronous calls are simple and couple availability; events decouple and make the flow harder to see.

Orchestration vs choreography

How services cooperate

Use orchestration when the workflow has an order, compensation steps and a business owner who asks "where is order 42 stuck?". Use choreography for fan-out where the producer should not care who reacts.

Orchestration: one component holds the workflow state and tells each service what to do, including the compensation when a step fails.
Choreography: each service reacts to events and emits its own. Every dashed arrow goes through the event bus, so publishers do not know their subscribers; the flow exists only as the sum of the subscriptions.
OrchestrationChoreography
Flow lives inOne place (orchestrator or workflow engine)Spread across subscribers
CouplingOrchestrator knows every participantProducer knows no consumers; consumers couple to event schemas
Adding a stepChange the orchestratorAdd a subscriber, no producer change
VisibilityWorkflow state is queryableNeeds tracing and correlation ids to reconstruct
Failure handlingExplicit retries, timeouts, compensation in one placeEach service handles its own; cyclic event chains are possible
RiskOrchestrator becomes a god service holding business logicNobody can say what happens after an event
Typical useCheckout, onboarding, money movementNotifications, analytics, search indexing, cache invalidation

Interview tip: most real systems mix them: orchestrate the critical path (reserve, charge, confirm) and publish an event at the end for everything else to choreograph around. An orchestrator can also drive steps asynchronously through queues; orchestration is not the same thing as synchronous.

Three kinds of event-driven

How services cooperate

"Event-driven" covers three different designs. Say which one you mean.

Event notificationEvent-carried state transferEvent sourcing
Event containsAn id and what happened: OrderPlaced {id: 42}The full state needed by consumers: order lines, totals, addressEvery state change of an entity, in order
Consumer thenCalls back to the producer for detailsUpdates its own local copy; no call backIs usually the same service, rebuilding its own state
ScopeBetween servicesBetween servicesInside one service: a persistence choice
GainSmall events, loose schema couplingConsumer works while the producer is down; fewer callsFull audit trail, time travel, rebuildable read models
PayCall-back load on the producer; reads may see newer state than the event describedLarger events, duplicated data, schema becomes a public contractComplexity: versioning, replay, eventual consistency
  • These are independent: you can publish integration events without event sourcing, and event-source one service without anyone outside knowing.
  • Do not expose internal event-sourcing events as the public contract. Publish separate, coarser integration events so the internals can change.
  • Delivery is at-least-once in practice, so consumers must be idempotent and tolerate reordering across partitions (see Distributed Systems Patterns).

CQRS

How services cooperate

Command Query Responsibility Segregation uses one model to validate and apply writes and one or more different models, shaped for the queries, to serve reads. The read models are derived from the write side.

Writes go to a store built for invariants; reads come from stores built for the query. The dashed path is asynchronous, so reads lag writes.
It pays whenIt does not pay when
Read and write load differ by orders of magnitude (100:1 or more)The app is CRUD and one schema serves both well
Reads need shapes the write model cannot serve: full-text search, feeds, aggregates across servicesA read replica or a cache would be enough
The write model has complex invariants you do not want bent to fit queriesUsers must always read their own write immediately everywhere
  • What you give up: read-your-writes. The read side lags by milliseconds normally and by minutes when a projector is behind or broken.
  • Mitigations: return the new state in the command response; read from the write store for the author's own recent data; pass a version and have the read API wait until the view has caught up; show "processing" in the UI.
  • The levels: same database with separate query classes, then read replicas, then separate stores. Only the last needs a change stream. CQRS does not require event sourcing.

Failure mode: a projector bug writes wrong data to the read store. You need monitoring of projector lag and a way to rebuild a view from scratch.

Event sourcing

How services cooperate

Store every change as an immutable event in an append-only log; current state is a fold over the events. Use it when the history is the business (ledgers, order lifecycles, audit-heavy domains). Avoid it as a default persistence choice.

The handler rebuilds the aggregate from a snapshot plus recent events, validates the command, and appends new events with an optimistic version check. Everything on the right is derived and rebuildable.
PiecePurpose
Event logSource of truth. Append-only, ordered per aggregate, optimistic concurrency on version
ProjectionA read model built by consuming events; this is where CQRS comes in
SnapshotCached state at version N so loading does not replay thousands of events; a pure optimisation, safe to delete
ReplayRebuild a projection, or build a new one, from event 1; also how you fix a projection bug

The hard parts

  • Schema evolution: events live forever, so old shapes must stay readable. Add optional fields only; for breaking changes, version the event type and "upcast" old events to the new shape on read.
  • Eventual consistency: projections lag. Uniqueness checks ("email not taken") cannot be done against a projection safely; they need a reservation aggregate or a constraint in a synchronous store.
  • Deletes and GDPR: an immutable log conflicts with the right to erasure. Options: keep personal data outside the log and reference it by id, or encrypt it per user and delete the key (crypto-shredding).
  • Replay side effects: a replay must not re-send emails or re-charge cards. Keep side effects in separate, idempotent consumers.
  • Querying: you cannot ask the log "all accounts over 1000"; every query needs a projection.
  • Fixing mistakes: never edit an event; append a compensating one.

Sagas, gateways and meshes

How services cooperate

PatternOne lineCovered in
SagaA multi-service transaction as a sequence of local transactions, each with a compensating action; orchestrated or choreographedDistributed Systems Patterns
API gatewaySingle entry point for clients: routing, authentication, rate limiting, TLS terminationAPI and Communication Design
Backend-for-FrontendOne gateway per client type (web, mobile) that aggregates and shapes responses for that clientAPI and Communication Design
Service meshSidecar proxies beside every service handle mTLS, retries, timeouts and telemetry for service-to-service trafficAPI and Communication Design

Sidecar, ambassador, adapter

How services cooperate

Three ways to add a helper container next to the application container, sharing its network and lifecycle, so cross-cutting behaviour is not compiled into every service in every language.

Containers in a pod share a network address and disk, so the application talks only to localhost and local files. The helpers face the outside world.
PatternDirectionJobExample
SidecarGeneralExtend or enhance the app without changing itLog shipper, config reloader, certificate rotation
AmbassadorOutboundProxy the app's calls to the outside: routing, retries, TLS, shardingLocal proxy to a database cluster; a mesh data-plane proxy
AdapterInbound view of the appNormalise the app's output to a standard interfaceExporter turning native stats into the monitoring system's format

Trade-off: you gain language-independent, separately upgradable infrastructure; you pay memory and CPU per pod (multiplied by every replica), an extra local hop of latency, and one more thing that can fail or start in the wrong order.

Platform patterns

Part 4 of 5 · what the services run on

An architect does not need to write manifests but must know what the platform gives for free (restarts, rollouts, discovery, scaling) and where isolation boundaries can be drawn.

Containers and orchestration

Platform patterns

A container packages a process with its dependencies; an orchestrator (Kubernetes is the usual reference) keeps a declared number of them running, replaces failures, rolls out versions and gives them a stable address.

Callers use the service name; pods come and go behind it. The deployment owns rollout and replica count; the autoscaler adjusts that count from metrics.
ObjectWhat it isWhat an architect should say
PodOne or more containers sharing a network address and volumes; the unit of schedulingPods are disposable. No local state that matters; graceful shutdown on SIGTERM
DeploymentDeclares image version and replica count; performs rolling updates and rollbacksReadiness probes gate traffic; liveness probes restart hung processes
ServiceStable DNS name and virtual IP load-balancing across ready podsThis is built-in server-side discovery
Ingress / gatewayHTTP entry from outside the clusterTLS termination and host or path routing
Horizontal autoscalerChanges replica count to hold a metric near a targetReactive, takes tens of seconds to minutes; needs resource requests set and a node autoscaler behind it
StatefulSetPods with stable identity and their own diskRunning databases on the orchestrator is possible but harder; managed services are the common default

Interview tip: one sentence is enough: "stateless services run as containers on an orchestrator with at least three replicas across zones, autoscaled on CPU or queue depth". Go deeper only if asked.

Service discovery and configuration

Platform patterns

Instances change address constantly, so callers look up a name, not an IP. Configuration follows the same rule: it lives outside the artifact so one build runs in every environment.

Client-side puts the load-balancing logic in every caller (or its sidecar); server-side hides it behind one address at the cost of an extra hop.
TopicOptionsNotes
DiscoveryDNS; a registry (Consul, etcd, ZooKeeper); platform services; meshDNS is simplest but TTL caching delays failover. Registries need health checks to evict dead instances
Static configEnvironment variables, mounted filesChanges need a restart or redeploy; versioned with the release
Dynamic configConfig service with watch or pollChanges in seconds without deploy; treat a config push like a code deploy: review, staged rollout, rollback
SecretsSecret manager, short-lived credentialsNever in the image or the repo; rotate automatically

Failure mode: the registry or config service becomes a single point of failure. Callers must cache the last known good answer and keep working when it is unreachable.

Feature flags

Platform patterns

A flag is a runtime switch that separates deploying code from releasing behaviour. It is the cheapest rollback there is: flip it off, no deploy.

Flag typePurposeLifetime
ReleaseHide unfinished work; ramp 1%, 10%, 100%Days to weeks, then delete
ExperimentA/B test by user cohortLength of the experiment
Ops / kill switchTurn off an expensive or optional feature under loadPermanent, tested regularly
PermissionEnable per tenant or planPermanent
  • Evaluate locally from a cached rule set; never make a network call per flag check. Default to the safe value if the flag service is down.
  • Bucket by a stable hash of user or tenant id so a user gets a consistent experience.
  • Cost: every flag doubles the paths to test. Stale flags are debt and a known incident cause; give each an owner and an expiry.

Flags as a deployment tool are covered in Reliability and Operations.

Multi-tenancy

Platform patterns

How much infrastructure tenants share is a trade between isolation and cost. Most B2B products end up with a pool for small tenants and silos for the few large or regulated ones.

Left to right: less isolation, lower cost per tenant, more tenants per unit of operations effort.
SiloBridgePool
IsolationStrongest: separate compute, data, often account or networkData isolated by database or schema; compute sharedLogical only: a tenant_id on every row and query
Cost per tenantHighest; idle capacity per tenantMediumLowest; best utilisation
Noisy neighbourNoneIn the app tierEverywhere unless limited
OnboardingProvision a stack (minutes to hours, automated)Create a schemaInsert a row
Operations at 10,000 tenantsHard: 10,000 deployments and migrationsHard: schema count limits, slow migrationsEasy: one of everything
Per-tenant restore, residency, custom keysEasyPossibleHard
FitsEnterprise, regulated, very large tenantsMid-market with compliance needsSelf-serve SaaS, many small tenants

The noisy-neighbour problem

In shared tiers one tenant's burst or heavy query degrades everyone. Controls, cheapest first:

  • Per-tenant rate limits and quotas at the gateway; per-tenant concurrency limits inside services.
  • Fair queueing: a queue per tenant or weighted scheduling, so one backlog cannot starve others.
  • Tenant-aware sharding, and moving a hot tenant to its own shard or silo.
  • Per-tenant metrics. Without a tenant label you cannot tell who the neighbour is.

Failure mode: in a pool, one query missing its tenant filter leaks data across customers. Enforce the filter below application code: row-level security, or a data-access layer that cannot run without a tenant context.

Cell-based architecture

Platform patterns

Run several complete, independent copies of the stack ("cells") and pin each tenant or user to one. A bad deploy, poison request or overload then hurts one cell, not everyone. With N equal cells the blast radius of a cell failure is about 1/N of users.

Cells share nothing with each other. The router is the only common component, so it must be as simple and as stable as possible.
  • Rules: no cross-cell calls on the request path; each cell has a fixed maximum size that has been load tested; scale by adding cells, not by growing them.
  • Deploys: roll out one cell at a time, starting with a canary cell, so a bad change is contained before it spreads.
  • Pays with: more infrastructure and lower utilisation, tooling to migrate tenants between cells, harder cross-cell features (global search, a tenant larger than one cell), and the router as a critical dependency.
  • Shuffle sharding is a related idea: give each tenant a different random subset of instances so two tenants rarely share all of them.

Senior signal: when asked "how do you limit the damage of a bad deploy or a poison tenant at very large scale?", cells plus staged rollout is the expected answer. It is the same thinking as bulkheads, applied to the whole stack.

Batch, nearline and online paths

Platform patterns

Decide per feature how fresh the result must be, then compute it on the cheapest path that meets that freshness. Precompute whatever you can; do online only what depends on the request.

Batch and nearline both write precomputed results into a serving store; the online path does a lookup plus the small amount of work that needs the live request.
PathFreshnessComputesStrengthWeakness
Batch (offline)Hours to a dayWhole dataset: model training, daily aggregates, full index rebuildsCheap per record, easy to re-run, complex logicStale; a failed run means yesterday's data
Nearline (streaming)Seconds to minutesIncremental updates per event: counters, feature updates, index deltasFresh without request-time costOrdering, late events, state management, reprocessing
OnlineNowPer request, inside the latency budget: ranking, filtering, permission checksUses live contextTight budget (tens of ms); cost scales with QPS

Edge compute: small functions running at CDN points of presence (redirects, auth checks, header rewriting, personalising cached pages) cut a round trip to the origin but have tight CPU and state limits; see Building Blocks for CDNs.

Choosing

Part 5 of 5 · picking a style and defending it

There is no best architecture, only one that fits the team, the load and the consistency needs today, with a clear path to the next step.

A decision flowchart

Choosing

Three "yes" answers are needed to justify microservices up front; otherwise start modular and extract only what earns it.
If the requirement isLean towards
Strong consistency across several entitiesKeep them in one service and one database; a saga is a cost, not a feature
Reads far outnumber writes, or need different shapesRead replicas first, then CQRS with projected views
Complete audit trail, "what was the state on date X"Event sourcing for that aggregate only
Spiky, infrequent or event-triggered workServerless functions or queue workers
Many consumers reacting to one factPublish an event; choreography
Very large scale, a failure must not hit all usersCells, staged rollouts
Enterprise tenants with isolation demandsPool by default, silo for the few

Anti-patterns

Choosing

Anti-patternHow it shows upFix
Distributed monolithServices that must be deployed together; lockstep versioningRe-draw boundaries around capabilities; versioned contracts; merge services that always change together
Shared databaseSeveral services writing the same tablesOne owner per table; others use its API or events
Chatty servicesOne user request causes dozens of internal calls; N+1 over the networkCoarser APIs, batch endpoints, local read copies, merge the services
God serviceOne service (often "core" or the orchestrator) that every feature must changePush logic back to the owning contexts; keep orchestrators thin
Premature splitMore services than engineers; boundaries wrong because the domain was not understoodStart as a modular monolith; split on a measured trigger
Synchronous chainsA calls B calls C calls D; latency adds, availability multiplies down (four hops at 99.9% is about 99.6%)Async where the caller need not wait; cache; fallbacks; flatten the call graph
Entity servicesServices named after tables, with business logic left in the callersSplit by capability, not by noun
Shared domain libraryA common library of business models that every service must upgrade togetherShare only infrastructure code; duplicate small domain types

Talking about evolution

Choosing

Interviewers want to hear a path, not a destination. Start with the simplest thing that meets the stated requirements, and for each step up name the trigger that would justify it.

Each arrow is labelled with its trigger. Being able to say the trigger is the difference between evolution and fashion.
StepTrigger to nameWhat you now pay
Replicas, cacheDatabase CPU dominated by reads; p99 read latency over targetReplication lag, cache invalidation
Queue and workersRequests doing slow or failure-prone work inline (email, thumbnails, third-party calls)At-least-once delivery, idempotency
Modular monolithMerge conflicts, unclear ownership, changes rippling across the codebaseDiscipline and tooling to enforce boundaries
First extractionOne module needs different scale, availability or release cadenceNetwork calls, a second pipeline, distributed tracing
Services per contextDeploy queue is the bottleneck; build and test times in tens of minutesPlatform team, sagas, eventual consistency
Sharding, CQRSWrite volume or data size past one primary; queries the write model cannot serveCross-shard queries, read lag
Cells, multi-regionOne failure affects all users; latency or residency requirementsCost, tenant migration tooling, replication conflicts

Interview tip: a sentence that works: "For the first version I would run this as one service with a replicated database; the first thing I would split out is X, when Y happens, because Z." It shows you know the complex design and chose not to pay for it yet.

Cheat sheet

Choosing

TopicRemember
Default shapeModular monolith until team count, scale divergence or fault isolation forces a split
Microservice testDeployable alone, owns its data, one team, one bounded context
Distributed monolithSeparate deploys, shared fate: shared DB, lockstep releases, sync chains
Hexagonal / cleanDependencies point inward; core defines ports, infrastructure implements adapters
Bounded contextWhere a model and its language are consistent; the service boundary candidate
AggregateUnit of transactional consistency; reference others by id; one transaction, one aggregate
Database per serviceNo shared tables; joins become API composition or local copies; transactions become sagas
Data ownershipOne writer per fact; copies are read-only and rebuildable
Strangler figFacade, move one route at a time, migrate the data, delete the old code
Anti-corruption layerTranslate at the boundary so a legacy or vendor model does not leak in
Orchestration vs choreographyCentral workflow with visible state vs decoupled reactions; orchestrate the critical path
Event notification / state transfer / sourcingId only and call back / full state in the event / the log is the database
CQRSSeparate read models fed asynchronously; you lose read-your-writes on the read side
Event sourcingAppend-only log, projections, snapshots, replay; hard: schema evolution, GDPR, lag
Sidecar / ambassador / adapterHelper container: extend / proxy outbound / normalise output
Multi-tenancySilo (isolated, costly), bridge (shared app, separate data), pool (shared, cheap, noisy neighbours)
CellsIndependent full stacks behind a thin router; blast radius about 1/N; deploy cell by cell
Serving pathsBatch (hours), nearline (seconds), online (milliseconds); precompute what you can
Sync chain arithmeticLatencies add, availabilities multiply: 0.999 to the power 4 is about 0.996
Evolution answerStart simple; name the trigger and the cost of each step

Next: how to keep whichever architecture you chose running, in Reliability and Operations.