Cruxly

Cruxly › System design › Principles of Distributed Design

State Gravity

state is the expensive thing; keep the set of things that have it small

Open the interactive lesson

The principle: every piece of state you add is a thing that must be replicated, backed up, migrated, made consistent, and recovered after a failure. Stateless components have none of those obligations. Therefore: keep the set of stateful components as small as the problem allows, and know exactly which ones they are.

The name is the point — state has gravity. It pulls complexity toward it: a stateless service can be killed and restarted with no ceremony, while a stateful one drags a recovery story, a replication story, and a migration story behind it forever.

The violation: state smeared across every service

The common version of this mistake does not look like a mistake. It looks like convenience.

API service        → holds user sessions in local memory
Recommendation svc → caches computed feeds in a local map
Upload service     → keeps partial uploads on local disk
Search service     → holds a locally-built index

The cost lands on the day you scale or a machine dies:

The deeper cost: you can no longer scale the halves independently. Traffic doubling is now a coordination problem — you cannot simply add stateless machines, because there are no purely stateless machines left.

The fix: push state into a small number of components that specialise in it

API service        → stateless; session token validated against a shared store
Recommendation svc → stateless; reads/writes a shared cache
Upload service     → stateless; parts go straight to object storage
Search service     → stateless query layer over a shared index cluster

Stateful set: [ session store, shared cache, object storage, index cluster ]

:::key The question this principle makes you ask Not "is this service stateless?" but "can I list, out loud, every stateful component in this design?" If the list is long, or if you have to think hard to produce it, state has smeared — and the recovery story is already more complicated than you believe it is. :::

What the principle costs, honestly

:::key The violation worth making out loud Local caches that are pure performance optimisation — where a cold instance is slower but never wrong — do not violate this principle, because they hold no truth. The test is not "is there data in memory" but "if this process dies, did the system lose a fact it cannot reconstruct?" If the answer is no, it isn't state in the sense that matters. :::

How to say it in the interview

"Before I scale anything, I want to separate the parts of this system that hold state from the parts that do not, because those two halves have completely different scaling and failure stories — the stateless half I can add machines to freely, and the stateful half is where all the real difficulty is going to live."

Checklist

Practice this interactively
Share this lessonWhatsAppLinkedInX

Related lessons