How-to

In-Memory Databases on a Dedicated Box

An in-memory database keeps its whole data set in RAM and uses disk only for safety copies. That makes reads and writes extremely fast and makes memory sizing the whole game.

What makes a database "in-memory"?

Its primary copy of the data lives in RAM, and every query is answered from memory. Disk-based databases also cache data in RAM, but their source of truth is on disk and their structures are designed around disk pages. An in-memory engine designs its structures for memory access instead, so operations take microseconds, and a single core can serve hundreds of thousands of simple requests per second. The trade-off: the data set must fit in RAM, with room to spare.

Which engines are common?

EngineModelPersistenceTypical use
RedisKey-value with rich data typesSnapshots and append logCaches, sessions, queues, rate limits
ValkeyRedis-compatible fork, BSD licensedSnapshots and append logSame jobs as Redis
MemcachedSimple key-value cacheNonePure caching, multi-threaded
DragonflyDB, KeyDBRedis-compatible, multi-threadedSnapshotsLarge single-node caches
TarantoolIn-memory with Lua and SQLWrite-ahead log and snapshotsTransactional workloads

Valkey appeared in 2024 after a Redis license change and is packaged by Debian 13 and by EPEL for Enterprise Linux 9; Redis itself returned to an open source license option with version 8 in 2025. Both speak the same protocol, so client libraries work with either.

How does an in-memory database survive a restart?

By writing to disk in the background. Redis and Valkey offer two methods, often used together:

  • Snapshots (RDB): a point-in-time dump written every few minutes. Fast to load, but changes since the last snapshot are lost on a crash.
  • Append-only file (AOF): every write is logged. With appendfsync everysec, at most about one second of writes is lost.
# /etc/valkey/valkey.conf (or /etc/redis/redis.conf)
save 900 1 300 100
appendonly yes
appendfsync everysec
maxmemory 96gb
maxmemory-policy allkeys-lru

On NVMe drives, which every model from S1 upward carries, both write quickly enough to stay invisible to clients.

Why do I need extra RAM beyond the data size?

Because snapshots fork the process. The child process writes the snapshot while the parent keeps serving; memory pages are shared until the parent changes them, at which point the kernel copies each changed page. On a write-heavy instance, a snapshot can briefly need up to twice the data size. Plan like this:

  • Data set plus 50 to 100 percent headroom for copy-on-write during snapshots.
  • Set maxmemory to roughly half of RAM on write-heavy instances, more on read-heavy ones.
  • Set vm.overcommit_memory = 1 so the fork is not refused, as Redis and Valkey recommend.
  • Disable transparent huge pages for these engines; huge copy-on-write pages make forks slower and spikier.

Which machine fits which data size?

A 40 GB cache fits comfortably on S5 with 128 GB DDR4. A busy session store or queue with a 60 GB data set and frequent snapshots wants S8. Hundreds of gigabytes, or many instances side by side, belong on the High memory line, for example M1 with 512 GB DDR4 or M4 with 48 cores for multi-threaded engines. The workload guide In-memory caches and stores goes deeper into sizing.

How do I use many cores with a single-threaded engine?

Redis and Valkey execute commands on one main thread, with I/O threads available for networking. To use a large machine, run several instances, one per core or pair of cores, each on its own port, and shard keys across them with client-side hashing or Redis Cluster. Bind each instance to cores on the same NUMA node as its memory on dual-socket boxes.

How do I protect it on a public address?

Never expose an in-memory database to the internet without authentication. Bind to 127.0.0.1 when clients are local; for remote clients, enable passwords or ACL users, turn on TLS, and allow the port only from client addresses in the firewall. Every machine has a single public IPv4 and no private network, so these steps are not optional. Exposed, password-less instances are one of the most common ways servers get compromised.

Machines Suited to In-Memory Stores

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
S5Intel Xeon E-2276G6 / 12128 GB DDR42x 1 TB NVMe2x 10 Gbps$88.72$88.72 (1 month)
S8Intel Xeon E-2388G8 / 16128 GB DDR41x 1 TB NVMe2x 10 Gbps$103.13$103.13 (1 month)
M12x Intel Xeon Gold 5315Y16 / 32512 GB DDR42x 4 TB NVMe2x 25 Gbps$414.70$414.70 (1 month)
M42x Intel Xeon Gold 6336Y48 / 96512 GB DDR42x 4 TB NVMe2x 25 Gbps$589.55$589.55 (1 month)

Keep Reading

In-memory caches and stores

Redis, Valkey or Memcached on machines with 128 GB to 1 TB of RAM, sized with snapshot headroom and NUMA in mind.

Open

Linux memory management

Virtual memory, pages, overcommit, huge pages, cgroup limits and the OOM killer: how Linux hands out RAM and the knobs worth turning.

Open

NUMA and dual-socket servers

Why two processors in one box share memory unevenly, and when a dual-socket machine beats a single big chip.

Open

High memory servers

512 GB to 1 TB of RAM, from $414.70 a month.

Open

FAQ

Quick Answers

A database whose main copy of the data lives in RAM, with disk used only for snapshots or logs.

Not if persistence is on. Snapshots and an append-only log let Redis or Valkey reload data after a restart.

The data set plus 50 to 100 percent headroom for copy-on-write during snapshots.

Yes. Valkey speaks the same protocol, so existing client libraries work with it.

Only with ACLs, TLS and a firewall allowing known client addresses. Bind to localhost when clients are on the same machine.