Skip to content

In-memory database

An in-memory database (IMDB) is a database management system that stores all data in RAM instead of on disk, achieving microsecond latency at the cost of durability and capacity limits.

Definition

What it is

Traditional databases read/write from disk (even SSD, ~100 µs–1 ms). An IMDB keeps data in RAM (~100 ns), gaining 1000x latency improvement. The trade-off: RAM is volatile and expensive. Persistence is added via write-ahead logs, snapshots, or replication — but you're always working with a cached copy of disk or a copy that could be lost.

Examples: Redis, Memcached, Hazelcast, VoltDB, SAP HANA, Aerospike, Dragonfly. Each optimizes for a different access pattern.

Why it matters

For a storefront recommendation call, 100 ms from disk is a lost sale; 1 ms from RAM is invisible. IMDBs make real-time personalization economically viable. Redis caching is the most common architecture: DB is source of truth, Redis is the fast layer.

In-memory vs disk-based vs hybrid

Aspect

In-memory

Disk

Hybrid

Latency

~100 µs

~10 ms

Varies

Capacity

RAM-limited

Disk-limited

Both

Durability

Snapshots + WAL

Full

Full

Cost/GB

High

Low

Medium

Example

Redis, Memcached

PostgreSQL, MySQL

SAP HANA

Where IMDBs sit in a stack

graph LR
  R[Request] --> I[IMDB fast]
  I -->|hit| Resp[Response]
  I -->|miss| D[Disk DB]
  D --> I
  D --> Resp
  style I fill:#E8F5E9

How to use an IMDB well

IMDB that scales

  1. Set eviction policy

    maxmemory-policy on Redis: allkeys-lru for caches, noeviction for critical.

  2. Persist what matters

    RDB/AOF for snapshots; replication for failover. Never treat IMDB as sole source of truth for critical data.

  3. Cluster for scale

    Single node = ~100 GB RAM. Shard above that.

  4. TTL on everything ephemeral

    Sessions, rate limits, temp tokens. Without TTL, RAM fills.

Common failures

Origin

The idea of keeping data in memory is as old as computing. Commercial IMDBs emerged in the 1990s for telecommunications (TimesTen, 1995). Memcached (2003) and Redis (2009) brought the pattern to web-scale caching. SAP HANA (2010) took it to enterprise analytics.

An in-memory database is a database management system that primarily relies on main memory for computer data storage.

— Wikipedia, *In-memory database*, 2024
1995 · TimesTen primer IMDB comercial
2003 · Memcached
2009 · Redis
2010 · SAP HANA
2024 · Dragonfly, Valkey (fork)

Evidence

FAQ

Are IMDBs durable?

Only with explicit persistence (snapshots, WAL, replication). RAM alone loses data on power loss.

When to use?

Hot data with tight latency needs: sessions, caches, real-time ranking, rate limiters.

Redis vs Memcached?

Redis has data types, persistence, pub/sub; Memcached is pure strings, simpler.

Can I use IMDB as primary DB?

Only with replication + persistence. Most teams use disk DB as source of truth and IMDB as cache.

Connections

Etymology

Origin: compound

  • in-memory (adjective): data stored in RAM
  • database (noun): from Latin basis, "foundation"

Semantic network

In-memory dadata-storeRedisCacheMemcacheddatabase

● broader ● narrower ● related

Broader

  • data-stores

Related

Sources