THUNDER(7)

Reference index
Contents

NAME

thunder — a key-value database

1. Description

Thunder is a key-value database. It stores a value under a key and, given the key, returns the value.

A key is a sequence of up to 65,535 bytes. A value is a nonempty sequence of bytes. It can hold text, JSON, a serialized object, an image, or a tensor. Thunder returns the bytes as written.

Thunder is built for the data that AI applications keep between runs. Conversation histories, source documents for retrieval, agent state, and model inputs and outputs can each grow to several megabytes or more.

When Thunder confirms a write, its journal record is already on disk. A confirmed write survives a crash or power failure on a drive that honors flush requests. Every connection uses TLS 1.3, and every stored value is encrypted.

Thunder runs on Linux, on a single machine.

2. Operations

OperationResult
SET k vStores v under k, replacing any earlier value.
GET kReturns the value under k, or reports that the key was not found.
APPEND k vAdds v to the end of the value under k, creating the key if it is absent. Returns the new length in bytes.
DELETE kRemoves k. Reports whether the key was present.
EXISTS kReports whether k is present without reading the value back.

Thunder finds values by key. It has no operation that lists keys or searches the contents of values.

3. Durability

For each write, Thunder records the operation in a journal on disk. It sends confirmation only after the drive reports that the record has been flushed. After a crash or power failure, Thunder replays the journal to recover the effects of confirmed writes. This requires a drive that honors flush requests.

On an orderly stop, Thunder stops accepting new requests, finishes the requests in progress, checkpoints the index, and exits.

4. Security

Clients connect over TLS 1.3. The server presents an Ed25519 certificate issued by a certificate authority (CA) that the clients trust. The installation creates the CA and the server certificate.

Thunder has no database passwords or access tokens. By default, any client that can reach the server’s ports can read and write every key. To restrict access to clients you authorize, enable mutual TLS. Each client must then present an Ed25519 certificate that chains to the CA you specify.

Thunder encrypts stored values with keys held in a keystore on the data volume. A passphrase unlocks the keystore at startup. Keep a separate, secure copy of the passphrase. You need it to read the data again, including from a backup.

5. How requests are executed

Thunder divides its keys into 1,024 shards. For a key k, the shard number is CRC32C(k) mod 1024.

A reactor is a server thread that executes requests. Each reactor owns a contiguous range of shards, its own memory arena, and its own port. Thunder uses one pair of available hardware threads per reactor group. One runs the reactor, and the other runs its background work.

The application gives the client one address, the server’s first port. The client discovers the shard map and connects to the reactors. It sends each request directly to the reactor that owns the key’s shard. Requests on different reactors can run in parallel.

6. Performance

We measured Thunder and Redis 7.0.15 on the same virtual machine. Each database served eight TLS connections, with one write outstanding per connection. Both flushed each write to disk before replying. The table gives p99 write latency, the time within which 99% of writes finished.

Value sizeThunder (ms)Redis (ms)Lower p99
4 KiB8.701.91Redis, 4.6×
2 MiB38.9121Thunder, 3.1×
16 MiB193778Thunder, 4.0×
64 MiB6552,929Thunder, 4.5×

Redis finished the smaller writes sooner at p99. Thunder had the lower p99 at every size tested from 2 MiB through 512 MiB. At the two largest sizes, Redis completed only 12–17 writes per run, so its reported p99 was its slowest write.

The benchmark report gives all seven sizes from 256 B to 512 MiB, the hardware, run lengths, and sample limits.

7. AI workloads

Conversation history. Give each conversation a key such as chat:4821. Append each message or tool reply as a record, with a newline or length field to mark its end. When the user returns, one GET retrieves the conversation. The application selects the messages to send to the model.

Retrieval-augmented generation (RAG). Put the source document in Thunder. For each passage, keep the key of that document revision and the passage’s byte range in the vector index. After a search, GET returns the document and the byte range locates the passage.

Agent checkpoints. After each step, the agent saves its state and next action under a run key with SET. If the worker stops, its replacement can read the last confirmed checkpoint and resume.

Batch inference. Store each prediction under a key formed from the run and item identifiers. On a retry, check those keys with EXISTS and send the missing items to the model.

Embeddings and generated output. Store a batch of embeddings, a generated image, an audio clip, or a long model response under one key. The application reads the value back whole.

8. Requirements and sizing

Software. Docker with Compose v2 and a Linux kernel of 6.8 or newer on the Docker host. On macOS or Windows, this is the kernel in Docker Desktop’s Linux VM.

Processor. x86-64 with AVX2, or ARM64 v8.2 with the Crypto Extensions. Supported ARM processors include AWS Graviton2 and Apple Silicon.

Memory. Thunder reserves each reactor’s arena at startup. The default is 4 GiB for a single reactor or 2 GiB each for two or more. A SET of n bytes needs space for two copies of the value in its reactor. Concurrent writes on that reactor add up. For 512 MiB values, allocate 4 GiB per reactor. Allow a few hundred MiB beyond the combined arenas for the server.

Disk. Use ext4 or XFS. Divide your peak live data size by 0.75 to size the volume. Add 4 GiB if you store values of 512 MiB or more. The sizing reference gives the settings in bytes.

9. Installation

In a POSIX shell, create a new directory and extract the release kit from the Thunder image on Docker Hub. Run the remaining commands from that directory.

mkdir thunderstrike && cd thunderstrike && \
  docker run --rm -v "$PWD:/out" \
    docker.io/sbansal793/thunderstrike:0.1.6 kit /out

Copy the settings to .env. The defaults are two physical cores and a starting port of 7380. The configure job reads the CPU topology and writes the port mapping.

cp .env.example .env
docker compose -f compose.yaml run --rm configure

Create the keystore passphrase once. Generate the certificates in docker/tls, then start the server.

mkdir -p docker/secrets docker/tls
(
  umask 077
  set -C
  openssl rand -base64 32 > docker/secrets/passphrase
)
docker compose run --rm tls-init
docker compose up -d
docker compose ps

When the server reports healthy, run the bundled client.

docker compose run --rm sample

For 30 seconds, the client writes 256 B, 4 KiB, 64 KiB, 2 MiB, and 16 MiB values. It reads each one back and compares every byte. Exit status 0 means every operation succeeded and every value matched. See the setup guide for the full procedure.

10. A first program

Install the Python client in your Python environment.

python -m pip install thunderstrike

Run this program from the release-kit directory. It writes the first message in a conversation, appends a reply, and reads both messages back.

from pathlib import Path
from thunderstrike import Thunderstrike

ca = Path("docker/tls/ca.crt").read_bytes()
with Thunderstrike(
    "127.0.0.1:7380",
    tls_server_name="localhost",
    tls_ca_pem=ca,
) as db:
    key = b"chat:4821"
    db.set(key, b"user: hello\n")
    db.append(key, b"assistant: hi\n")
    print(db.get(key))

Output

b'user: hello\nassistant: hi\n'

The client reference also gives working examples for Node.js, Go, Rust, .NET, Java, PHP, C, and C++.

11. Errors

ErrorMeaningWhat to do
BusyA server queue was full or another request won a race for the same resource.Back off before retrying. By default the client retries up to four times within five seconds for operations other than DELETE.
ServerOutOfMemoryThe owning reactor waited for memory and could not obtain enough.Reduce concurrent writes or increase the memory per reactor.
StorageExhaustedThe store reached its storage limit. Reads still work.Free space or expand the volume.
ServerErrorA device, integrity, or internal check failed.Read the server log.
Timeout, DisconnectedThe write may already have taken effect.Check the application state before retrying a write. Repeating APPEND can add the same bytes twice. A second DELETE can report that the key was absent.

12. Backup and restart

Stop the server and copy the entire data volume, or take a consistent filesystem snapshot and copy the snapshot. Copying files individually while the server writes can produce an inconsistent backup. To restore, put the copy in place of the volume and start the server with the same keystore passphrase.

docker compose ps reports healthy once every reactor has finished recovery and its port is accepting connections. Use docker compose logs thunderstrike to read the server log.

Before upgrading, back up the volume and stop the old server. Extract the new kit beside the old one. Copy over .env, docker/secrets, and docker/tls. Set THUNDERSTRIKE_IMAGE in .env to the new release, run configure, and start the server on the same volume. See the operations reference.

13. License

Thunder is proprietary software of SHORTSQUEEZE PRIVATE LIMITED. You can run it free of charge, including in production and as the database behind your own application. The license agreement permits changes to deployment settings. It restricts modification of the software, reverse engineering, resale, and offering Thunder itself as a hosted database service.

SEE ALSO