---
title: "Example — failover-demo"
---

# Example — failover-demo

Manual primary-failover demo with Transaction Write Replay (TWR) on the proxy side.

**Source on GitHub**: [`HeliosDB-Proxy/examples/failover-demo`](https://github.com/HeliosDatabase/HeliosDB-Proxy/tree/main/examples/failover-demo)

## Demonstrates

- Application connects to the proxy on `:5432` and starts a long-running transaction
- Operator triggers `pg_promote` on the standby; primary goes down mid-transaction
- HeliosProxy detects the failover and, with `tr_mode = "transaction"`, replays the uncommitted transaction against the new primary — verifying each replayed response against the digest of what the client already saw, and rolling back with SQLSTATE `40001` on any divergence
- The application keeps its connection and the transaction commits on the new primary; had the COMMIT itself been in flight, the client would get SQLSTATE `08007` and the COMMIT would not be retried
- Had the transaction been opened at `SERIALIZABLE` or `REPEATABLE READ`, it would not have been replayed at all — no replacement backend can reproduce that snapshot
- This needs no cargo feature: Transaction Replay, including the separate write journal and the `/api/replay` endpoint below, is part of the default build (`ha-tr` is a deprecated no-op)

## Run

```bash
cd HeliosDB-Proxy/examples/failover-demo
./run-demo.sh
```

The driver script narrates each step. Watch the proxy admin UI's **Topology** panel to see the failover in real time. The **Time-Travel Replay** panel reads the separate recovery journal, which is populated by the write path rather than by the session recovery — it is a different view, not a trace of the replay you just watched.

## Why it matters

This is the demo that maps directly to **Innovation #6 (Transaction Write Replay)** in the HeliosProxy IP portfolio — Oracle TAF/TAC-equivalent failover transparency without per-application code changes.
