Quickstart
Record a real crash, replay it with no broker, and watch Kavach accept a correct fix and reject one that is too narrow. About five minutes.
The demo is a wallet ledger. It folds a stream of JSON events (deposit, withdraw, transfer) into balances. One upstream event arrives with "amount": null, and the handler crashes on it.
You will build three versions of the ledger: the one with the bug, a correct fix, and a fix that is too narrow. The commands use the Go version; every SDK ships a port of the same demo with the same bug.
1. Get the demo#
You need Go 1.24 or later to build the demo (your own services do not need Go).
git clone https://github.com/kavachlabs/kavach && cd kavach
go install ./cmd/kavach ./cmd/kavach-recorder # or use the install script
go build -o ledger-old ./examples/ledger/sdk
go build -tags ledgerfix -o ledger-new ./examples/ledger/sdk
go build -tags ledgerpartialfix -o ledger-partial ./examples/ledger/sdkledger-new rejects any event with no amount. ledger-partial rejects it only for deposits, the event type in the incident.
2. Record the crash#
./ledger-old -in examples/ledger/testdata/events.jsonlThe ledger panics on the eighth event. Before the process dies, the flight recorder writes a fixture to kavach/fixtures/ledger-*.kavach.
3. Read what happened#
kavach inspect kavach/fixtures/ledger-*.kavachinspect prints the journal record by record: each input, the clock and random reads the handler made, its outputs, and the marker that says how the step failed. Add --full for the panic stack, or --json to parse it.
4. Replay it#
kavach replay kavach/fixtures/ledger-*.kavach --bin ./ledger-oldservice ledger · start genesis · 34 records · 8 steps replayed
recorded panic at seq 32: runtime error: invalid memory address or nil pointer dereference
result still_failing@32--bin is a host command: Kavach starts your own build in replay mode and feeds it the recorded inputs, answering every clock, random and config read from the fixture. Outputs are captured, never delivered, so replay touches no external system. still_failing@32 means the step for the input at sequence number 32 (the eighth event, evt-008) fails, just as it did in production.
5. Verify the correct fix#
kavach diff kavach/fixtures/ledger-*.kavach --old ./ledger-old --new ./ledger-newold still_failing@32
new fixed
first divergence at step seq 32: output 0 of step 32 differs
old (none)
new ledger.rejections {"event":"evt-008","reason":"missing amount"}
variants 51 of 61 reproduce the incident on the old build · 51 of those pass on the new build
regressions 47 of 47 match the old build · 48 variants of 4 earlier inputs resembling the failing one
verdict fixeddiff replays the fixture on both builds. It also builds variants of the incident (the bad event's fields changed, the event moved earlier, earlier events dropped or redelivered, the clock shifted) and keeps those on which the old build fails the same way. Then it checks regression variants: the same changes applied to earlier events that look like the failing one, which the old build handled fine. The new build passes every reproducing variant and leaves every regression variant unchanged, so the verdict is fixed.
6. Watch a narrow fix fail#
kavach diff kavach/fixtures/ledger-*.kavach --old ./ledger-old --new ./ledger-partialnew fixed
variants 51 of 61 reproduce the incident on the old build · 44 of those pass on the new build
✗ 7 failing input (seq 32): "type" "deposit" → "transfer"
still_failing@23: panic: runtime error: invalid memory address or nil pointer dereference
saved /tmp/kavach-variants-…/ledger-…-000032.variant-07.kavach
…
verdict variant_failed(7)@23The partial fix passes the recorded crash (new fixed). But variant 7 is the same null amount on a transfer, and the partial fix still crashes on it. Kavach saves every failing variant so you can replay it directly:
kavach replay /tmp/kavach-variants-…/ledger-…-000032.variant-07.kavach --bin ./ledger-partialPass --keep DIR to choose where variants are saved, or --json and read variants.checks[].file.
7. See the flow#
kavach map examples/ledger/.kavach/plan/map.json examples/ledger/testdata/null-amount.kavach \
--bin ./ledger-old --new ./ledger-new -o ledger-map.html
open ledger-map.htmlkavach map draws one self-contained HTML page: how events flow from entry points through handlers, state and sinks to invariant checks, with each recorded step and the fix's effect on it. See Flow maps.
The same demo on Kafka#
The ledger can also read a Kafka topic, which is its journal: on every start it folds the topic from the first offset. With a local broker:
docker run -d -p 9092:9092 apache/kafka:3.9.0
./ledger-old -kafka localhost:9092 -seed examples/ledger/testdata/events.jsonl # load the topic once
./ledger-old -kafka localhost:9092 # crashes at offset 0:7The fixture's inputs carry their Kafka positions (kafka:wallet-events @ 0:7), and it still replays with no broker running. Kafka is a dependency of the demo only, not of the SDK.
Next#
- Concepts: the words used in the rest of the docs.
- Instrument a service: record your own.
- Fix an incident: the loop, step by step.
Something wrong or missing on this page? Report it on GitHub, or write to hello@thekavachlabs.com.