Architectural Patterns
The handful of shapes almost every system settles into — and how to tell which one a problem is asking for.
Architectural patterns in 30 seconds
- Client-server: the base of nearly everything — clients ask, servers answer.
- Monolith: one deployable unit. Simple and fast to start; harder to scale teams and parts independently.
- Microservices: many small, independently deployable services. Scales teams and parts; adds network, ops, and data complexity.
- Serverless: you write functions, the cloud runs and scales them. Great for spiky/event work; watch cold starts and lock-in.
- Event-driven: services react to events instead of calling each other directly. Loose coupling; eventual consistency.
- Rule of thumb: start with a modular monolith; split into services when team size or scaling pain demands it — not before.
Floor plans for software
Before an architect draws a single wall, they pick a kind of building: a studio flat, a terraced row of houses, a tower block. Each shape makes some things easy and others hard — the studio is cheap and quick but can't house a growing family; the tower scales to thousands but needs lifts, fire systems, and a management company. Software has the same handful of floor plans, and picking one is the first real design decision you make. It quietly sets the difficulty of everything that follows.
This page walks the common shapes, the pain each one is a response to, and how to tell which a problem is actually asking for. The goal isn't to memorize them — it's to recognize the problem each shape solves so you reach for the simplest one that fits.
Start with the honest truth
There's a myth that 'real' systems must be microservices. They don't. These patterns aren't a ladder you climb — they're tools, each solving a particular kind of pain. The best architects pick the simplest shape that meets the requirements and only add complexity when something concrete forces their hand. Let's walk the main shapes and what each one is actually for.
Client-server: the foundation
Almost everything is built on this. Some machines (clients — browsers, apps) make requests; other machines (servers) do the work and respond. Every pattern below is really a different way of organizing the server side. Worth stating because interviewers like to see you anchor on fundamentals before reaching for buzzwords.
The gap a growing monolith can't fill
A monolith — one codebase, one deployment, everything together — is the right starting point for almost every system. It's simple to build, trivial to deploy, easy to debug (one place to look), and your database can do clean joins and transactions across all your data. For a long time, it's genuinely the best choice. So why does anyone ever leave it? Because a few specific pains show up only at a certain size:
- Teams collide. Twenty engineers editing one codebase step on each other — merge conflicts, a shared release train, one team's bug blocking everyone's deploy.
- You can't scale parts independently. The image-processing code needs 10× the CPU, but because it's welded to everything else, you have to scale the whole app to give it more — paying for capacity the rest doesn't need.
- One crash takes it all down. A memory leak in a rarely-used report feature can topple the entire application, because it all runs in one process.
- Deploys get scary. A one-line change means redeploying the whole thing, so releases slow down and batch up, which makes each one riskier.
Notice every pain is about independence — teams, scaling, failure, and deploys all wanting to move separately but being fused together. That's the exact gap microservices fill. They don't make a monolith's code simpler; they let its parts move on their own.
Monolith vs microservices: the big one
A monolith is one codebase, one deployment — all the features living together. A microservices architecture splits those features into separate services that deploy and scale on their own. The honest comparison:
| Monolith | Microservices | |
|---|---|---|
| Getting started | Fast and simple | Slow; lots of upfront setup |
| Deploying | One unit (all or nothing) | Each service independently |
| Scaling parts | Scale the whole thing | Scale only the hot service |
| Team autonomy | Teams step on each other | Teams own services independently |
| Debugging | One place to look | Trace across the network |
| Data | One database, easy joins/txns | Per-service data; distributed txns |
The in-between: a modular monolith
The split isn't all-or-nothing. A modular monolith keeps everything in one deployable unit — so you keep simple deploys, debugging, and transactions — but organizes the code into clean modules with strict boundaries, as if each module were a future service. You get most of the organizational clarity without the network and ops tax, and if a module later needs to scale or deploy on its own, it's already shaped to be lifted out.
// Modules talk through interfaces, not by reaching into each other's tables.
// This is the seam you'd cut along IF you ever extract a service.
public class OrderService {
private final PaymentModule payments; // an interface, not a DB handle
private final InventoryModule inventory;
public void placeOrder(Order order) {
inventory.reserve(order.items()); // today: an in-process call (fast, transactional)
payments.charge(order.total()); // tomorrow: swap for a network call if extracted
}
}
// One deploy, one database, clean seams. Extract a module only when a real
// pain (team size, independent scaling) justifies the network hop.Event-driven: react instead of call
Instead of the order service directly calling email, shipping, and analytics, it simply announces 'OrderPlaced' to an event bus, and each interested service reacts. This is the loosest coupling you can get — adding a new reaction means adding a subscriber, with zero changes to the source. The cost is that the flow becomes harder to follow end-to-end and everything is eventually consistent. (See Pub/Sub & CDC.)
# Synchronous: order service calls each dependency directly
def place_order(order):
save(order)
email.send(order) # must know about, and wait for, each one
shipping.create(order) # a new consumer means editing THIS function
analytics.track(order) # one slow call blocks the whole response
# Event-driven: order service just announces what happened
def place_order(order):
save(order)
bus.publish("OrderPlaced", order) # fire and forget; add subscribers
# without ever touching this codeServerless: don't manage the servers
- What it is: you write small functions; the cloud runs them on demand and scales them automatically, and you pay per execution.
- Great for: spiky or event-triggered work, glue between services, cron-style jobs, low-traffic APIs.
- Watch out for: cold starts (a first call after idle is slow), execution time limits, and vendor lock-in.
- Not ideal for: long-running, stateful, or latency-critical workloads.
// You deploy ONLY this handler. The platform runs it on each event,
// spins up more copies under load, and bills per invocation.
export async function handler(event) {
const image = await fetchFromStorage(event.key);
const thumb = await makeThumbnail(image); // spiky, event-triggered work
await saveToStorage(event.key + "-thumb", thumb);
return { status: "ok" };
}
// No idle servers to pay for. But the FIRST call after a quiet spell pays a
// 'cold start' delay while the platform boots a fresh instance.Peer-to-peer: no central server
In P2P, nodes talk directly to each other with no central coordinator — each peer is both client and server. It shines for sharing load and data across many equal participants (file sharing, some blockchains, certain streaming systems). It's a niche choice for most products, but worth recognizing so you can name it when a problem genuinely has no natural center.
Choosing a shape
Match the pain to the pattern. The honest default is the simplest thing that meets the requirements, and you move only when a concrete pain — not a trend — pushes you:
| Situation | Reach for | Because |
|---|---|---|
| New product, small team, unclear requirements | Modular monolith | Fastest to build, deploy, and change; keeps seams for later |
| Many teams colliding; parts need separate scaling | Microservices | Independent deploys and scaling, at an ops cost |
| Spiky, event-triggered, or glue workloads | Serverless | Scales to zero and to spikes; pay per call |
| Many reactions to one event; loose coupling wanted | Event-driven | Add reactors without touching the source |
| Specialized tier (GPU model serving, search) | A dedicated service | Its scaling profile differs too much to share a box |
Architectural patterns are the vocabulary of the whole discipline — before you argue about caches or shard keys, you've already chosen a shape, and that choice quietly decides which problems are easy and which are painful for the life of the system.
Why it matters
- The pattern you pick sets the default difficulty of everything after it — deploys, scaling, debugging, and data all inherit its trade-offs.
- It's the first real decision in most design discussions, and the one most likely to be made by fashion instead of fit.
- Knowing the shapes lets you match a problem to the simplest structure that solves it, rather than reaching for the trendy one.
If ignored
- Cargo-culting microservices onto a small team and drowning in operational complexity you didn't need.
- Clinging to a tangled monolith long after teams are stepping on each other and parts need to scale alone.
- Choosing serverless or event-driven for work they're wrong for — long-running jobs, or flows you need to trace simply.
Where it fits
- Sits at the very top of a design — the frame that every component decision then lives inside.
- Shapes the org as much as the code: service boundaries tend to mirror team boundaries.
- Revisited at inflection points — growth, new teams, new scaling pain — not casually mid-flight.
Related topics
- The key trade-offs: every pattern is a bundle of the trade-offs catalogued there
- Message queues: the backbone that makes event-driven and async patterns work
- API gateway: the front door that makes a microservices split manageable
- Pub/Sub & CDC: the mechanics underneath event-driven architecture
Interview lens
Questions it unlocks
- Monolith or microservices for this — and why?
- When would you choose serverless?
- What does event-driven architecture buy you, and what does it cost?
60-second answer
I treat these as tools, not a ladder. I'd start most systems as a modular monolith because it's simple to build, deploy, and debug, and split into microservices only when team size or independent scaling genuinely demands it — being explicit that microservices trade code complexity for network and operational complexity. I'd pull out a model-serving or other specialized tier as its own service, use event-driven flows for loose coupling where eventual consistency is fine, and reach for serverless on spiky or glue workloads while watching cold starts and lock-in.
Common traps
- Defaulting to microservices for a small team that a monolith would serve better.
- Forgetting that splitting services moves complexity onto the network and ops.
- Choosing serverless for long-running, stateful, or latency-critical work.