Space-Based
Grid de datos en memoria
Escrito por Darjus Kazakevic · revisado el
Take the database off the request path, and scale by adding units.
Most systems end up waiting on one thing: the central database. Space-based architecture takes it off the request path. State lives in an in-memory data grid (the “space”), replicated across processing units that read and write at memory speed. A separate process writes changes to a real database in the background. Products such as Hazelcast, Apache Ignite and GigaSpaces provide the grid.
With no central store to wait on, you scale by adding units, and throughput grows almost linearly. The price is complexity. You must decide how data is split and replicated, what happens when a node dies before its changes are saved, and how memory limits your data size.
En esencia — Keep application state in a replicated in-memory data grid instead of a shared database, so processing units scale almost linearly under extreme, spiky load.
Cuándo recurrir a él
Recurre a él cuando
- Extreme, spiky load: ticket sales, flash sales, online betting
- Throughput beyond what a central database can sustain
- Low, predictable latency matters more than instant durability
Reconsidéralo cuando
- Ordinary applications; the complexity is almost never worth it
- Every write must be durable before you answer the user
- Heavy reporting that needs rich relational queries
The moving parts
- Processing units
- Each unit holds the application logic plus an in-memory copy of the data it needs. Any unit can serve any request, so you add units to add capacity.
- The data grid (in-memory data grid)
- A distributed, replicated store in memory that all units share. Reads and writes take microseconds instead of a database round trip of milliseconds.
- Data pump
- A background process writes grid changes to a durable database, out of the request path. The database is seconds behind the grid by design.
- Virtualized middleware
- The layer that routes requests to units, keeps replicas in sync and adds or removes units as load changes. It makes many nodes look like one store.
Making the grid pay off
- Keep the database off the request path
- Reads and writes must hit memory. One synchronous database call in the hot path brings back the bottleneck the whole design exists to remove.
- Plan partitioning and backups up front
- Decide which key splits the data and how many backup copies each partition has. This is where naive designs lose data when a node dies.
- Design for the persistence lag
- The database is behind the grid. Decide what happens to changes that a dead node had not yet written, and keep reports on the grid or a replica.
- Use it only under real pressure
- This is the most complex style in this category. First try a database with a cache and read replicas; reach for a grid when load still exceeds what they can handle.
Errores habituales
- One synchronous database call that brings the bottleneck back
- Partitions without backups, so a node crash loses recent writes
- Business logic that assumes the database is current when it is seconds behind
- Using it where a database plus a cache would have been enough