Loading content...
If data is the core of systems, persistence is its heartbeat. But here's a nuance that separates thoughtful system design from naive implementation: not all data has the same durability requirements.
Consider the difference between:
All four are 'data.' But treating them identically—storing all with the same durability guarantees—would be either wasteful (over-engineering ephemeral data) or dangerous (under-protecting critical data).
Understanding persistence requirements is about matching durability guarantees to actual business needs—and accepting the trade-offs each choice entails.
By the end of this page, you will understand the spectrum of persistence requirements, from ephemeral storage to ironclad durability. You'll learn how to classify data by its persistence needs, understand the costs of different durability levels, and make informed trade-offs between safety, performance, and complexity.
Persistence exists on a spectrum from completely ephemeral to absolutely permanent. Each position on this spectrum comes with different costs, performance characteristics, and engineering complexity.
The spectrum:
| Level | Durability | Survives... | Typical Use Case | Technologies |
|---|---|---|---|---|
| Ephemeral | None | Nothing—request only | Request-scoped computation | In-memory variables |
| Request Cache | Minutes | N/A (expires quickly) | Repeated computations in request | Process memory |
| Session | Session duration | Page refreshes | Shopping cart, form state | Session storage, Redis |
| Cached | Hours to days | Restarts (if backed) | Computed results, API responses | Redis, Memcached |
| Persistent | Indefinitely | Crashes, restarts | User data, transactions | PostgreSQL, MySQL |
| Durable | Across failures | Disk failures (replication) | Financial records | Replicated databases |
| Immutable | Forever | Everything—append-only | Audit logs, blockchain | Append-only stores, WORM |
Moving along the spectrum:
As you move from ephemeral toward immutable, you gain durability but pay costs:
The art of system design involves placing each piece of data at the appropriate position on this spectrum—durable enough to meet requirements, but no more durable than necessary.
Every data type has a 'Goldilocks zone'—durable enough, but not excessively so. Session data in an ACID database is overkill. Financial transactions in Redis are negligent. Finding the right fit for each data type is a core competency of system designers.
When databases and storage systems talk about 'durability,' they're making specific promises about what happens after data is written. Understanding these promises—and their limitations—is essential for choosing appropriate storage.
The fundamental question:
If I receive confirmation that my write succeeded, under what conditions might that data still be lost?
Different systems answer this question differently:
The physics of durability:
At a physical level, durability requires getting data out of volatile memory (RAM) and onto persistent media (disk, SSD, or replicated across network). Each step adds latency:
| Operation | Typical Latency | What It Survives |
|---|---|---|
| Write to RAM | ~100 nanoseconds | Nothing (volatile) |
| Write to OS buffer cache | ~1 microsecond | Process crash (not system crash) |
| fsync to local SSD | ~100 microseconds | Local process/system crash |
| fsync to local HDD | ~10 milliseconds | Local process/system crash |
| Replicate to 1 remote node | ~1-10 milliseconds | Local node failure |
| Replicate across regions | ~50-200 milliseconds | Regional failure |
Notice the 1,000x difference between RAM and local disk, and another 100x for cross-region replication. Durability is purchased with latency.
Some databases offer 'durable' modes that aren't truly durable. Writing to the OS page cache without fsync looks fast but can lose data on power failure. Default Redis configuration writes asynchronously—acknowledged writes may be lost. Always verify what durability actually means for your storage system.
A systematic approach to persistence starts with classifying your data. Each category has different requirements, and misclassifying data leads to either wasted resources or unacceptable risk.
The classification framework:
| Category | If Lost... | Examples | Minimum Durability |
|---|---|---|---|
| Regenerable | Can be fully recreated from source | Caches, computed aggregations, search indexes | None (ephemeral OK) |
| Reconstructable | Can be rebuilt with effort/cost | Analytics summaries, denormalized views | Best-effort (soft durability) |
| Replaceable | Would be inconvenient but recoverable | User preferences, UI settings | Session/local storage |
| Valuable | Would cause user frustration | Draft documents, form progress | Persistent (single node OK) |
| Critical | Would cause business/user harm | User accounts, orders, payments | Durable (replicated) |
| Irreplaceable | Would cause regulatory/legal issues | Financial transactions, audit logs | Immutable (multi-region) |
Applying the classification:
Let's classify data for a typical e-commerce system:
Regenerable (cache/compute):
Reconstructable (soft persist):
Valuable (persistent):
Critical (durable/replicated):
Irreplaceable (immutable/multi-region):
Notice that a single application spans the entire persistence spectrum. Treating all data identically would mean either over-engineering the regenerable data or under-engineering the irreplaceable data.
For any system you're designing, explicitly list every data type and classify it. This exercise often reveals assumptions that haven't been examined. 'We're storing that in Redis? What happens when Redis restarts?' becomes a productive conversation rather than a production incident.
Durability isn't free. Understanding its costs helps you make informed trade-offs rather than defaulting to maximum durability (expensive) or minimum durability (dangerous).
Cost dimensions of durability:
Quantifying the difference:
Let's compare write performance across durability levels for a typical workload:
| Durability Level | Writes/Second (Single Client) | Writes/Second (Parallel) |
|---|---|---|
| In-memory only | 500,000+ | 2,000,000+ |
| Write to page cache | 200,000+ | 800,000+ |
| fsync per write (SSD) | 5,000-10,000 | 50,000-100,000 |
| fsync per write (HDD) | 100-200 | 500-1,000 |
| Synchronous replication (local) | 2,000-5,000 | 20,000-50,000 |
| Synchronous replication (regional) | 50-200 | 500-2,000 |
Numbers are illustrative; actual performance depends on hardware, workload, and configuration.
Notice the orders-of-magnitude differences. Choosing 'maximum durability by default' can reduce write throughput by 1,000x compared to in-memory. This is why persistence requirements must be intentional, not accidental.
The cost of fsync is largely per-operation, not per-byte. Writing 1,000 records with one fsync is nearly as fast as writing 1 record with one fsync—but 1,000x faster than 1,000 records with 1,000 fsyncs. This is why databases group commits and why message queues batch writes. Batching amortizes durability costs.
Real systems use multiple persistence patterns, often layered together. Understanding common patterns helps you design systems that balance performance with appropriate durability.
Pattern 1: Write-Ahead Logging (WAL)
The most fundamental database durability pattern:
WAL enables durability without synchronous updates to complex data structures. The log is append-only (fast), while actual data structures are updated lazily.
Pattern 2: Write-Behind Caching
For write-heavy workloads where some data loss is acceptable:
Used for: Analytics events, metrics, non-critical logs. Redis with RDB snapshots works this way.
Pattern 3: Synchronous Replication
For data that must survive single-node failure:
Used for: Financial transactions, user-critical data. PostgreSQL synchronous replication, Vitess, CockroachDB.
Pattern 4: Event Sourcing
For complete auditability and reconstructability:
Used for: Audit systems, financial ledgers, systems requiring complete history. Event stores, Kafka with proper configuration.
Pattern 5: Tiered Persistence
Combining multiple persistence levels for hot vs cold data:
Used for: Time-series data, logs, analytics. InfluxDB, Prometheus + Thanos.
Production systems often layer these patterns. A database might use WAL for local durability, synchronous replication for node-level durability, and asynchronous cross-region replication for disaster recovery. Understanding the patterns lets you reason about the composite behavior.
One of the most important trade-offs in distributed systems is between durability and availability. Stronger durability guarantees often require more coordination, which can impact availability.
The fundamental tension:
| Configuration | Durability | Availability | Latency | When to Use |
|---|---|---|---|---|
| Single node, fsync | Survives crash | Single point of failure | Low | Development, non-critical |
| Async replication | May lose recent writes | High (reads continue on failover) | Low | Read-heavy, eventual consistency OK |
| Sync replication (1 replica) | Survives 1 node failure | Reduced (need 2 nodes up) | Medium | Critical data, local region |
| Sync replication (2+ replicas) | Survives 2+ node failures | Lower (need 3+ nodes) | Higher | Financial, regulated industries |
| Multi-region sync | Survives region failure | Lowest (cross-region latency) | High | Global, disaster-resistant |
Practical decision framework:
When configuring durability, ask:
What's the cost of losing data? — Financial loss, user impact, regulatory consequences, reputation damage.
What's the cost of unavailability? — Lost revenue, user frustration, SLA penalties, operational disruption.
What latency can users tolerate? — 100ms? 500ms? Synchronous cross-region replication may push writes beyond acceptable latency.
What budget is available? — Multi-region synchronous replication requires 2x-3x infrastructure cost plus expensive cross-region networking.
The honest answer for most systems:
This tension connects to the CAP theorem: during a partition, you must choose between consistency (durability of the latest write) and availability. Most systems choose availability (serving potentially stale data) over consistency (refusing to serve until sync is confirmed). Know your system's choice.
Durability isn't just about preventing data loss during normal operation—it's about recovering when things go wrong. A complete persistence strategy includes backup and recovery planning.
Types of failures to plan for:
Recovery metrics:
Two key metrics govern backup strategy:
Recovery Point Objective (RPO) — How much data can you afford to lose? Measured in time. RPO of 1 hour means you can lose up to 1 hour of data.
Recovery Time Objective (RTO) — How long can recovery take? Measured in time. RTO of 4 hours means service must be restored within 4 hours of incident.
Backup strategies mapped to RPO/RTO:
| Strategy | Typical RPO | Typical RTO | Use Case |
|---|---|---|---|
| No backup | N/A (total loss) | N/A | Ephemeral data only |
| Daily snapshots | Up to 24 hours | Hours | Development, staging |
| Point-in-time recovery (PITR) | Minutes | Hour+ (depends on archive) | Business-critical databases |
| Synchronous replica | Zero (for replicated data) | Minutes (failover) | High availability |
| Multi-region sync | Zero | Minutes to hours | Disaster recovery |
| Air-gapped backup | Daily/weekly | Hours to days | Ransomware protection |
A backup that has never been restored is a hope, not a guarantee. Schedule regular restore drills. Verify backup integrity. Test that restored data is actually usable. Many organizations have discovered during an incident that their 'backups' were corrupted, incomplete, or unrestorable.
Let's consolidate the concepts into a practical decision framework for choosing persistence requirements.
Common mistakes to avoid:
Default durability syndrome — Using PostgreSQL with synchronous replication for ephemeral session data. Wasteful and slow.
Optimistic durability — Assuming Redis or in-memory storage is 'good enough' for order data. Dangerous.
Backup theater — Running backup scripts that create files no one ever restores or verifies.
Single-tier thinking — Trying to use one storage system for all durability levels. Inefficient.
Ignoring recovery time — Having backups but no tested recovery procedure. Recovery during an incident is not the time to learn.
Forgetting about corruption — Replication propagates corruption. You need point-in-time recovery for application-level bugs.
You now understand the full spectrum of persistence requirements, from ephemeral caching to ironclad multi-region durability. You can classify data by its persistence needs, understand the performance and cost trade-offs, and design systems with appropriate durability for each data type. Next, we'll explore query and access patterns—how the ways you read data shape your storage choices.