cloudparts

Sub-millisecond lookups

Answering reads and writes by key in well under a millisecond, for sessions, rate limits, leaderboards and caches in front of slower stores.

What it asks of a system

Below a millisecond, the data has to live in memory and the request has to be simple: get or set one key, bump a counter, push onto a list. In-memory stores such as Redis and Memcached do the work itself in microseconds or less, so most of the time is spent on the network and the operating system. Redis’s own docs put a typical 1 Gbit/s network round trip at about 200 µs, and a busy virtual machine can add milliseconds of its own. Pipelining, batching several keys per request and keeping connections open matter more than the server’s raw speed.

What breaks low latency is anything that blocks the server: a command that walks a large collection, a fork for a snapshot on a big instance, swapping, or an fsync on every write. A cache in front of a database, such as DynamoDB Accelerator, can bring reads from single-digit milliseconds down to microseconds, but its reads are only eventually consistent and it helps only when most requests hit the cache.

When you compare systems, look at p99 and p99.9 latency measured from the client in the same zone, under the target load, with persistence and replication switched on as they would be in production. Check how it behaves while a replica is resyncing or a snapshot is being written, and whether the client library supports pipelining.

Good at it · 6

Compare side by side

Key-value stores

AerospikeCommercialThe primary index stays in RAM and clients send each request straight to the node that owns the key, so a lookup is one hash and one device read.A distributed key-value database written in C that keeps its index in RAM and its records on SSDs, for steady sub-millisecond lookups on terabytes of data.Amazon ElastiCacheAWSManaged Valkey, Redis OSS or Memcached inside your VPC, with microsecond reads and writes from memory.AWS’s managed Valkey, Redis OSS and Memcached, as node-based clusters or a serverless cache.Amazon MemoryDBAWSThe whole dataset sits in RAM behind Valkey and Redis commands, so reads take microseconds; writes wait for a Multi-AZ log.A Valkey- and Redis-compatible database that keeps everything in memory but loses no acknowledged write.MemcachedOpen sourceEvery command is O(1) on a multithreaded server, and clients hash keys across servers that never coordinate.A simple, multithreaded in-memory key-value cache; clients hash keys across independent servers.RedisOpen sourceThe whole dataset sits in RAM and each command is a small atomic operation, so reads and writes take well under a millisecond.An in-memory data-structure server: the default cache, and also queues, counters and leaderboards.ValkeyOpen sourceData lives in RAM, and I/O threads take network work off the main thread, so one server handles 1.2 to 2.1 million requests a second.The Linux Foundation’s BSD-licensed fork of Redis 7.2.4: an in-memory key-value server that Redis clients can talk to unchanged.

Sources

Why each technology is listed comes from the sources on its own page.