tsnap makes a Typesense restart take seconds instead of hours. Typesense rebuilds every search index in memory each time it starts, and for large vector collections that can take most of a working day. tsnap saves the running Typesense process itself, memory included, and after a power cut, crash or reboot it brings that process back exactly as it was. We built it at CodeWiz, and it is free and open source on GitHub.
Contents
Typesense is a fast, open-source search engine, and many teams now use it for vector search as well as for keyword search. Its speed comes from keeping indexes in RAM. The price is paid at startup: after every reboot the server reads all documents from disk and builds those indexes again, and until it finishes, search is down.
This post explains the problem, how tsnap solves it without changing Typesense, and what it takes to run it. It is written for developers and system administrators who run their own Typesense server, especially with large collections or vector fields.

Why Typesense takes hours to come back
Typesense keeps its search indexes, including the HNSW index used for vector search, only in memory. The documents themselves are stored on disk in RocksDB, and on every start Typesense reads them back and rebuilds the indexes from scratch. For small collections that takes seconds. For large vector collections it takes hours, because building an HNSW graph is expensive.
We built tsnap for a server with exactly this problem. One collection of 5.5 million documents with 512-dimension vectors (M=64, ef_construction=800) took about 7 hours to come back after every power cut, crash or reboot. Every reboot, even one for a routine kernel update, meant hours without search.
Typesense’s own snapshot API does not help here. It saves the data on disk, which is good for backups, but starting from that copy still means rebuilding every index in memory. A faster restart needs the memory itself.
What tsnap does
tsnap saves the running Typesense process: its complete memory, plus the data folder exactly as it was at that moment. It uses CRIU (Checkpoint/Restore In Userspace), a Linux tool that can save a running program to disk and start it again later from the same point. Typesense itself is not modified.
The data folder is not copied. RocksDB never changes a data file after writing it, so a snapshot gives each file a second name (a hard link). That is instant and takes no extra space at first. Only the memory is written out.
- Drop-in: install it next to a running Typesense; nothing is restarted.
- Short freeze: Typesense is frozen for about 0.5 seconds per snapshot at 1 million documents, and about 1.5 to 2.5 seconds is projected at 5.5 million. Requests that arrive during the freeze wait; they are not dropped.
- Announced: a local HTTP endpoint tells your services when a snapshot or restore is in progress, so they can pause and resume.
- Exact: after a restore, queries return exactly what they returned at snapshot time.
- Careful with the host: it never runs apt and never installs or upgrades system packages, and a read-only
tsnap doctorchecks the machine before anything is set up.
How a snapshot and a restore work
A snapshot runs every few hours from a systemd timer (every 6 hours by default), before every planned stop, and whenever you run sudo tsnap snapshot:
- tsnap copies all of Typesense’s memory to disk while Typesense keeps serving.
- It freezes Typesense for a moment and saves only the memory that changed in the meantime, plus a hard-linked copy of the data folder taken at that same frozen instant.
- It unfreezes Typesense, checksums everything, writes a manifest and makes the snapshot visible in one atomic rename. A half-written snapshot is never used.

A restore runs after a reboot when you type sudo tsnap restore, and automatically after a crash:
- tsnap picks the newest snapshot that passes verification. A corrupt snapshot is marked BAD and skipped.
- It stops any Typesense that is running or still loading, and swaps in a fresh copy of the snapshot’s data folder atomically. The replaced folder is kept and put back if every restore attempt fails.
- CRIU recreates the process in its own private process-ID and clock space, so it keeps its original process IDs without clashing with other programs after a reboot, and its clock never runs backwards.
- tsnap waits for Typesense to report healthy and checks the document counts.
One thing to keep in mind: a restore brings back the state of the snapshot, so writes made after the last snapshot are gone. Planned restarts and reboots are the exception, because tsnap takes a final snapshot first. After an important import, run sudo tsnap snapshot.
Measured numbers
The benchmarks ran in a VM with 4 vCPUs (Ryzen 5700X) and an NVMe disk, on Ubuntu 24.04 with Typesense 29.0, using 512-dimension cosine vectors with M=64. “Freeze” is the longest stall seen by a client sending searches back to back.
| Documents | 500k | 750k | 1M | 5.5M (projected) |
|---|---|---|---|---|
| Typesense memory = snapshot size | 1.7 GB | 2.4 GB | 3.2 GB | ~16.6 GB |
| Freeze (no client errors) | 0.32 s | 0.38 s | 0.45 s | ~1.5–2.5 s |
| Whole snapshot, serving throughout except the freeze | 4.0 s | 5.0 s | 6.4 s | ~30 s |
| Restore after a reboot, with verification | 4.4 s | 5.3 s | 7.4 s | ~35–60 s |
| Normal cold start | 48 min | hours |
At 1 million documents, a restore took 7.4 seconds where a normal cold start took 48 minutes: 32 minutes to become healthy, then another 16 replaying its raft log. A cold start of the data folder that tsnap leaves behind produced exactly the same documents as the restore.
Letting your services wait out a freeze
A freeze of a second or two is harmless for most applications, but an import job or a queue worker is better off pausing than timing out. tsnap runs a small status endpoint on http://127.0.0.1:8109 that any local program can ask:
GET /statusreturns the current state.GET /readyreturns 200 if Typesense can be used and 503 if not.GET /wait?timeout=60waits until Typesense is ready.GET /eventsstreams Server-Sent Events, one per change.
The repository includes a dependency-free Node.js helper. One gate per process, checked before each Typesense call, costs nothing while Typesense is ready and waits during a freeze or restore:
import { createGate } from './tsnap-client.mjs';
const gate = createGate();
await gate.whenReady(); // instant while ready; waits during a freeze or restoreA “frozen” answer cannot outlive the real freeze. tsnap only reports it while a snapshot is really running, and if tsnap itself dies, waiting clients are woken within about 0.1 seconds. The usage guide also has examples for shell scripts, Python and systemd services.
What happens when things go wrong
A tool that stops and starts your search server has to fail safely. Each of these cases is covered by the tests:
- Power cut during a snapshot: the half-written snapshot is ignored, and restore uses the previous one.
- Power cut during a restore: the data folder is never missing, thanks to the atomic swap; run the restore again.
- Every restore attempt fails: the data folder from before is put back.
- Corrupted snapshot: caught by checksums, marked BAD and never used.
- Disk full during a snapshot: the snapshot fails cleanly and Typesense keeps serving.
- The final snapshot of a planned stop fails: nothing older is restored automatically, because that would silently lose writes. You choose between accepting the loss and a full reload.
- Typesense came up empty after a problem: snapshots are refused, so a broken state never pushes good snapshots out.
- Kernel, glibc or Typesense updated by apt: restores work across kernel updates, and the exact libraries and binary the process used are kept with the snapshot. tsnap also stops needrestart from restarting Typesense, which would mean a full reload.
- Closed terminal or Ctrl+C during a snapshot: nothing happens, because snapshots and restores run as systemd jobs and the terminal only shows their progress.
Supported systems and limits
tsnap is tested on Ubuntu 22.04, 24.04 and 26.04 and on Debian 12, with Typesense 27.1, 28.0, 29.0, 29.1 and 30.2. Every combination passed all 42 checks in a fresh VM, including snapshots under load, exact restores, crash recovery, killing CRIU in the middle of a freeze and a restore after a reboot.
- Typesense installed from the official
.debpackage and running astypesense-server.service, on a single node (not a cluster). - systemd with cgroup v2, a stock kernel of the systems above, and root access.
- Free disk space of about 2.5 times Typesense’s memory for two snapshots, on the same filesystem as
/var/lib/typesense. For a 16 GB Typesense, that is about 45 GB. - Restores run on the machine that took the snapshot. Kernel updates are fine; moving to another CPU is not.
- Docker setups and Typesense clusters are not supported.
How to start
git clone https://github.com/codewizdevs/tsnap && cd tsnap
./install.sh --interval-hours 6 # asks for sudo; Typesense keeps running
sudo tsnap snapshot # first snapshot of the running Typesense
tsnap status- Install with
install.sh. It puts a single Python 3 file in/usr/local/sbin/tsnap, downloads CRIU into its own folder with its signature and checksum verified, runstsnap doctor(about 22 read-only checks) and stops if anything fails. - Take the first snapshot at a quiet moment. For a 16 GB Typesense it takes about 30 seconds, with a freeze of 1.5 to 2.5 seconds.
- Test one restore in a maintenance window: pause your writers, then run
sudo tsnap snapshot && sudo tsnap restore. Expect 1 to 2 minutes of downtime. This proves restores work on your data and switches Typesense to the service that restores itself after a crash. - Connect your services to the status endpoint if they write to Typesense.
- After a reboot, run
sudo tsnap restore. After a crash, there is nothing to do.
Why CodeWiz
- Built from a real problem. tsnap exists because of a 7-hour Typesense cold start, and its first fix release came from something we saw on a real server.
- Tested before it was published. Every system and Typesense version in the support table, each in a fresh VM, plus power cuts during snapshots and restores, and restores across kernel versions.
- Search and hosting next to the tool. CodeWiz was founded in 2023 by Dragan Plavšić in Banja Luka. We build site search with Typesense, run hosting and look after servers for clients, so tsnap comes from the same work.
- Open source. tsnap is free under the MIT License. Issues and pull requests are welcome.
Frequently asked questions
Does tsnap change Typesense?
No. It saves and restores the running process with CRIU, and the Typesense binary and its data format stay as they are. It adds a systemd drop-in to typesense-server.service so that a planned stop takes a final snapshot first.
Is it free?
Yes. tsnap is open source under the MIT License.
What do I lose on a restore?
Writes made after the last snapshot. Planned restarts and reboots lose nothing, because tsnap takes a final snapshot first. For anything else, run sudo tsnap snapshot after important updates, or shorten the interval with sudo tsnap schedule 4.
Does it work with Docker or Typesense Cloud?
No. tsnap needs a single-node Typesense installed natively from the official .deb package, on a server where you have root.
Can I restore a snapshot on another server?
No. A snapshot is restored on the machine that took it. Kernel updates on that machine are fine.
Is tsnap made by Typesense?
No. tsnap is an independent project by CodeWiz. It is not affiliated with or endorsed by Typesense, and “Typesense” is a trademark of its owners.
Get tsnap
The code, the install script and the full documentation are on GitHub, and the usage guide covers day-to-day commands and integration. If your team needs help with a slow Typesense restart, search with vector fields, or the servers behind it, contact us, or see our wider services.