When I first started learning backend development, the architecture felt simple:
Frontend → Backend → DatabaseThen I discovered Cloudflare Workers, Durable Objects, KV storage, distributed systems, stateless architecture, load balancing, and edge computing.
At first it felt confusing because it didn't behave like traditional Express.js servers.
This blog explains the mental model shift from traditional backend development to modern distributed systems architecture.
Traditional Backend Architecture
Most beginners learn backend development using:
- Node.js
- Express.js
- PostgreSQL
A typical Express server looks like this:
app.get("/users", (req, res) => {
res.json(users)
})The important thing to understand is:
You are running a server.Your Node.js process:
- stays alive continuously
- listens on a port
- handles requests
- manages memory
This is a traditional server architecture.
The Problem with Traditional Servers
Traditional servers work well initially, but problems appear when applications grow.
What happens if:
- millions of users arrive?
- your server crashes?
- users are globally distributed?
- traffic spikes suddenly?
One server becomes:
- overloaded
- geographically distant
- a bottleneck
This is where distributed systems begin.
What is a Distributed System?
A distributed system means:
Multiple computers working together as one system.Instead of:
One server handling everythingyou now have:
Many servers handling traffic togetherThis introduces:
- horizontal scaling
- load balancing
- synchronization problems
- shared state issues
Horizontal Scaling
Instead of upgrading one machine:
More RAM
More CPUmodern systems usually scale horizontally:
1 server → 10 servers → 100 serversThis is how large internet systems scale.
Load Balancing
If you have many servers, traffic must be distributed.
That is the role of a load balancer.
Example:
Users
↓
Load Balancer
↙ ↓ ↘
Server A
Server B
Server CThe load balancer decides:
- which server handles requests
- how traffic gets distributed
- failover handling
Why Stateless Systems Scale Better
Modern distributed systems prefer stateless servers.
Stateless means:
Each request is independent.The server does not rely on local memory between requests.
Benefits:
- any server can handle any request
- easier horizontal scaling
- simpler load balancing
This is why JWT authentication became popular.
Instead of the server remembering sessions:
- the token carries identity information
- any server can verify it
Perfect for distributed systems.
The Shared State Problem
Distributed systems become difficult when multiple machines need to modify the same data.
Example:
- chat rooms
- counters
- multiplayer games
- collaborative editing
Now synchronization becomes necessary.
Race Conditions
A race condition occurs when multiple operations modify shared state simultaneously, causing unpredictable results.
Example:
count++If two requests run at the same time:
- both may read the same old value
- both may overwrite each other
The final result becomes incorrect.
The key idea is:
Timing changes behavior.Why Cloudflare Workers Exist
Cloudflare Workers take a very different approach from traditional servers.
Instead of:
- managing VPS servers
- configuring infrastructure
- scaling manually
Cloudflare handles:
- infrastructure
- scaling
- load balancing
- deployment
- global edge distribution
You only write request handlers.
Example:
export default {
async fetch(request) {
return new Response("Hello")
},
}This means:
"When a request arrives, run this code."There is no traditional server management.
Workers are Stateless
Cloudflare Workers are designed to run globally across many machines.
Because of this, Workers avoid shared memory.
Why?
Because synchronizing shared memory across worldwide servers becomes:
- slow
- complex
- unreliable
Instead, Workers are:
Independent stateless executions.This allows massive scalability.
Hono: Express for Edge Runtimes
Raw Workers can become difficult to structure as applications grow.
That is why frameworks like Hono exist.
Hono provides:
- Express-like routing
- middleware
- TypeScript support
- cleaner structure
Example:
const app = new Hono()
app.get("/", (c) => {
return c.text("Hello")
})Most developers should use Hono instead of raw Workers for real projects.
Cloudflare KV
Cloudflare KV is globally distributed key-value storage.
Best for:
- caching
- configuration
- fast global reads
- feature flags
Mental model:
Global distributed cache/storageKV is optimized for:
- extremely fast reads
- eventual consistency
Not strong realtime coordination.
Durable Objects
Sometimes applications NEED shared state.
Examples:
- chat rooms
- multiplayer games
- websocket coordination
- realtime collaboration
This is where Cloudflare Durable Objects come in.
Durable Objects provide:
One coordinated stateful object instance.The key property is:
Requests are processed one-at-a-time per object.This prevents race conditions.
Single-Threaded Consistency
Durable Objects guarantee:
Only one request modifies object state at a time.Example:
Request A finishes
THEN Request B runsThis makes shared state predictable and safe.
The Big Architectural Principle
Modern backend architecture separates:
Stateless Compute
- Workers
- scalable request handling
from
Stateful Coordination
- databases
- Durable Objects
- Redis
- queues
because globally shared memory is extremely difficult to scale safely.
This is one of the core ideas behind distributed systems engineering.
Final Thoughts
The biggest mindset shift for me was realizing:
Modern backend engineering is mostly distributed systems engineering.Once concepts like:
- stateless systems
- load balancing
- shared state
- race conditions
- distributed coordination
become clear, technologies like:
- Cloudflare Workers
- Durable Objects
- KV
- edge computing
suddenly make much more sense.
The internet at scale is really about one problem:
How do many computers cooperate safely and efficiently?That is distributed systems design.