Book Deep Read · Fundamentals of Software Architecture · Chapter 15
Fundamentals of Software Architecture · Ch 15 · Mark Richards & Neal Ford · 2020
Tickets for a superstar's concert go on sale at 10 a.m. A ticketing site that is quiet most of the day suddenly gets hundreds of thousands of visitors in a single second. Most websites spin, throw errors, or simply fall over. The space-based architecture in this chapter is a way of building software for exactly this situation: "usually idle, suddenly packed."
When a site is slow, the first instinct is to add servers. But past a certain point, adding more does nothing. The front servers can be multiplied freely, yet they all end up asking the same database. It is like a store opening a hundred checkout lanes while a single stockroom clerk answers every "is this in stock?" question. More lanes just make the line at the clerk's door longer.
The database is the hardest part of a system to copy into several pieces: it has to keep every account balanced, and extra copies must constantly check with each other, which makes things slower, not faster. So however much you grow the front, the bottleneck sits at that one point, and a surge takes the whole thing down.
Space-based architecture makes a bold move: while doing the work, don't talk to the database at all. The system is split into many identical "processing units." Each one is like an independent ticket counter with a complete copy of the ledger on the desk, kept in memory so it can be flipped through instantly. When it sells a ticket, it writes it in its own ledger first, then calls out so the other counters update theirs too.
And the database? It moves to the back office and becomes the archive. After a counter records a sale, it drops a slip on a conveyor belt, and back-office clerks copy the slips into the archive in order. The archive can lag a little, but the counters never wait in line for it.
When the crowd grows, a "shift manager" opens new counters on the spot; when it thins out, some are closed to save money. A new counter just copies the ledger from the counter next door and starts selling.
It gives perhaps the strongest surge-handling of any style in the book, ideal for ticket sales and auctions where crowds swing wildly and answers must be instant. The honest cost: when two counters change the same line at the same moment, one change can occasionally overwrite the other, and the whole setup is hard to build, hard to test and not cheap. If your ledger is huge and changes heavily all day, this is not your tool.
Space-based = every processing unit carries an in-memory ledger and keeps it in sync with the others, while the database catches up in the background: you trade consistency and simplicity for the elasticity to survive sudden spikes.
Want the processing unit and the four middleware roles, how data pumps and readers/writers turn the database into a back office, how to estimate the collision rate, replicated vs distributed caching, and the book's star ratings? → Switch to Deep
You think handling high concurrency means "add more servers," but in the end the bottleneck is always the database every request must reach synchronously. Space-based architecture does not make the database faster; it takes it out of the request path. Data lives in an in-memory grid inside each processing unit, replicated asynchronously between them, and the database is written behind the scenes. FoSA Chapter 15 covers the parts of this structure, why it achieves near-unlimited elasticity, and what it pays for that: data collisions, eventual consistency and complexity.
The sixth style in Part II, "Architecture Styles," right after event-driven architecture (Ch 14) and before orchestration-driven SOA and microservices (Ch 16 and 17). Real-world match: ticket sales, online auctions, flash sales and trade matching, where user volume is unpredictable and the peak can be a hundred times normal.
A typical web system has three tiers: web servers → application servers → database. As users grow, the bottleneck shows up tier by tier. The web tier is easiest to scale, the application tier harder, the database hardest, because it must protect transactions and consistency and splitting it horizontally is very costly. The book draws this as an inverted triangle: narrower toward the bottom, with all traffic finally squeezed into one point.
For a ticketing system at 1,000 concurrent users on a normal day and 100,000 the instant sales open, that triangle is fatal. Adding 100 application servers just exhausts the database's connection pool sooner: the result is system-wide timeouts, not speed. Buy a database sized for the peak? You use it a few hours a year, it is expensive, and it still has a ceiling.
The name comes from tuple space, a technique in which multiple parallel processors communicate through shared memory. The goal: stop the scalable parts from being throttled by the one part that cannot scale.
The book breaks the style into five components: processing units (holding the application code), virtualized middleware (managing and coordinating the units), data pumps (sending updated data to the database asynchronously), data writers (performing the database writes) and data readers (reading data from the database and delivering it to the units). The central idea fits in one line: a processing unit never touches the database while handling a request.
A processing unit holds the business logic. It may contain the whole application (for small systems) or be split by function into several kinds (an order unit, a payment unit, somewhat like microservices). The key is that it also embeds an in-memory data grid and a replication engine; the book's examples are Hazelcast, Apache Ignite and Oracle Coherence.
The book demonstrates with Hazelcast: instances of the same unit declare the same named cache, discover each other at startup and form a cluster. When any instance changes data, the replication engine pushes the change asynchronously to the other members of that named cache. Each instance therefore holds an (almost) complete copy, so whichever instance a request lands on can read and write right there in memory.
When a unit changes data in memory, that change must eventually reach the database. The unit doesn't write directly; it drops the update into a data pump, typically a message queue. The book stresses that data pumps are always asynchronous, so cache and database can only be eventually consistent. Messages need guaranteed delivery and FIFO ordering, and the pump decouples units from writers. Pumps are usually set up per domain or subdomain (one for "customer," say).
Data writers take messages off the pump and perform the database writes, either one per domain or one dedicated to each kind of unit. Data readers go the other way, sending database data back to the units through a "reverse data pump," and the book says they are invoked in only three situations: every instance of a named cache has crashed; every instance of a named cache is being redeployed; or archive data not held in the replicated cache is needed. Normally a new instance syncs its cache from its peers, not from the database.
Together, readers and writers form a data abstraction layer: units don't know the table schema, so the database can evolve step by step without touching business code.
When many instances can write the same data and replication is asynchronous, you get data collisions: before one instance's update has replicated, another instance changes the same row based on the old value, and the later replication overwrites the earlier change.
The book gives a formula to estimate the collision rate: collision rate = N × UR² / S × RL. In plain words: more instances (N), more frequent updates (UR) and slower replication (RL) mean more collisions; more cache rows (S) mean less chance of hitting the same row. Update rate is squared, so it matters most. The book's example: 5 instances, 20 updates per second, a 50,000-row cache and 100 ms replication latency give about 14.4 collisions per hour out of 72,000 updates (about 0.02%). By the same formula, dropping to 2 instances or cutting latency to 1 ms lowers collisions sharply; shrink the cache to 5,000 rows and they rise to about 144 per hour.
The formula's value is that it turns "will it collide?" from a guess into a number you can argue about: if the rate is acceptable, use a replicated cache; if not, reduce instances, shorten replication latency, or switch to a distributed cache.
The book spends a full section on this choice. A replicated cache keeps a full copy in each unit's memory; reads and writes are local, very fast and fault tolerant, since any surviving instance holds everything. A distributed cache keeps data in an external, central cache cluster that every unit accesses remotely; there is only one copy, so it is consistent, but each access costs a network round trip, and a problem in the cache servers hits everyone.
Table 1 · Replicated vs distributed cache (organized along the book's decision criteria)
| Criterion | Replicated cache | Distributed cache |
|---|---|---|
| Optimizes for | Performance (local memory) | Consistency (a single copy) |
| Cache size | Small (around a hundred MB or less): every instance must hold it all | Large (GB and beyond) |
| Kind of data | Relatively static | Highly dynamic |
| Update rate | Low: frequent updates collide and swamp replication | High |
| Fault tolerance | High: every instance has everything | Low: the central cache is a shared dependency |
| Cost | Collisions; memory × number of instances | Remote latency; the central cache needs its own HA |
The book's advice is pragmatic: mix both in one system. Small, rarely updated data (a product catalog) goes in a replicated cache; volatile data that must be consistent (inventory) goes in a distributed cache. The book also explicitly advises against a near-cache (a small local front cache per instance backed by a full cache): each instance's front cache evicts by recent use, so contents differ between instances, and the same request routed to different instances sees different response times and data.
Table 2 · Scenario check
| Scenario | Verdict | Why / cost |
|---|---|---|
| Ticket sales, flash sales | Good fit | Low normally, explosive at sale time; the deployment manager adds and removes instances, so cost follows traffic |
| Online auctions | Good fit | Unpredictable bid volume, instant answers; bids are ordered in memory and history is written asynchronously via pumps |
| Traditional apps with huge data | Poor fit | The full data set won't fit in each instance's memory, so replicated caching breaks down |
| Strongly consistent accounting | Use with care | Cache and database are only eventually consistent; collisions need extra handling |
| Ordinary systems with steady load | Not worth it | Complexity and cost far exceed the gain; layered or service-based is enough |
The book also mentions a deployment variant: processing units and middleware run in the cloud while the database stays on premises, connected by data pumps. You get cloud elasticity and still meet rules that require data to stay on site.
In the star ratings, space-based scores 5 stars for elasticity, scalability and performance, the top marks among the book's styles, while simplicity and testability get only 1 star and cost is high. The testing difficulty is concrete: proving it survives requires simulating production-scale peak concurrency, which test environments often cannot produce, so much load testing ends up happening in production.
In an architecture review, ask four things: how many times normal is the peak, and how fast does it arrive? Does the full data set fit in each instance's memory? What does the formula say about collision rate, and can the business live with it? If every cache dies, how long does refilling from the database take? In an interview, asked "how do you survive a flash sale?", you can say: "Hot data lives in an in-memory grid replicated asynchronously across instances, so requests never touch the database; updates go through an ordered queue and are written asynchronously; I choose replicated vs distributed caching by the collision rate, and handle high-churn, must-be-consistent fields like inventory separately."
1. Scale a traditional three-tier system far enough and the bottleneck is always the synchronously accessed database; space-based takes it off the request path.
2. Five parts: processing units, virtualized middleware, data pumps, data writers, data readers.
3. Processing unit = business logic + in-memory data grid + replication engine; instances of a named cache replicate asynchronously, and requests complete in local memory.
4. Four middleware roles: messaging grid (intake / balancing / sessions), data grid (most important), processing grid (optional orchestration), deployment manager (elasticity).
5. Data pumps are always async, guaranteed and ordered, so cache and database are only eventually consistent; readers appear only after total crash, total redeploy, or for archive data.
6. Collision rate rises with instance count, the square of update rate and replication latency, and falls with cache rows; the book's example is about 0.02%.
7. Replicated caches favor performance and fault tolerance for small, static data; distributed caches favor consistency for large, volatile data; mix them, and avoid near-caches.
8. Ratings: elasticity, scalability, performance 5 stars; simplicity, testability 1 star; high cost. Great for tickets and auctions, poor for ordinary data-heavy apps.
9. Interview line: "Hot data in an in-memory grid with async replication, database written behind via a queue; compute the collision rate, then choose replicated or distributed caching."