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?
| Engine | Model | Persistence | Typical use |
|---|---|---|---|
| Redis | Key-value with rich data types | Snapshots and append log | Caches, sessions, queues, rate limits |
| Valkey | Redis-compatible fork, BSD licensed | Snapshots and append log | Same jobs as Redis |
| Memcached | Simple key-value cache | None | Pure caching, multi-threaded |
| DragonflyDB, KeyDB | Redis-compatible, multi-threaded | Snapshots | Large single-node caches |
| Tarantool | In-memory with Lua and SQL | Write-ahead log and snapshots | Transactional 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
maxmemoryto roughly half of RAM on write-heavy instances, more on read-heavy ones. - Set
vm.overcommit_memory = 1so 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
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| S5 | Intel Xeon E-2276G | 6 / 12 | 128 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $88.72 | $88.72 (1 month) |
| S8 | Intel Xeon E-2388G | 8 / 16 | 128 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $103.13 | $103.13 (1 month) |
| M1 | 2x Intel Xeon Gold 5315Y | 16 / 32 | 512 GB DDR4 | 2x 4 TB NVMe | 2x 25 Gbps | $414.70 | $414.70 (1 month) |
| M4 | 2x Intel Xeon Gold 6336Y | 48 / 96 | 512 GB DDR4 | 2x 4 TB NVMe | 2x 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.
OpenLinux memory management
Virtual memory, pages, overcommit, huge pages, cgroup limits and the OOM killer: how Linux hands out RAM and the knobs worth turning.
OpenNUMA and dual-socket servers
Why two processors in one box share memory unevenly, and when a dual-socket machine beats a single big chip.
OpenFAQ
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.