Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-redis-postgres-pgpool-docker/llms.txt

Use this file to discover all available pages before exploring further.

backtest-kit Redis + PostgreSQL + Pgpool replaces the default file-based ./dump/ persistence in backtest-kit with PostgreSQL (via TypeORM) as the durable source of truth and Redis as an O(1) ID lookup cache. It ships 16 persist adapters that implement the full IPersist*Instance contract, a Pgpool-II streaming-replica dev cluster, and ready-to-use Docker Compose files so the entire stack starts with one command.

Introduction

Understand the architecture, design goals, and how the persistence layer fits into backtest-kit.

Quickstart

Start the infrastructure and run your first backtest in under five minutes.

Persistence Layer

Learn how the 16 adapters map backtest-kit contracts to PostgreSQL tables and Redis cache.

Atomicity

Deep-dive into the ON CONFLICT upsert pattern that prevents race conditions on replica clusters.

Docker Layout

Understand the three Docker Compose files and how the containers are wired together.

Configuration

Full reference for all environment variables consumed by the app and container stack.

How it works

1

Start the infrastructure

Spin up the Pgpool-II cluster (1 primary + 2 streaming replicas) and Redis with two docker-compose commands. First boot takes ~60–90 seconds while the replicas clone.
2

Register the persist adapters

src/config/setup.ts registers all 16 Persist*Adapter implementations against backtest-kit’s adapter hooks. No changes to strategy code are required.
3

Run in your chosen mode

Use --backtest, --live, or --paper flags (or the MODE env var in Docker) to select the execution mode. The same adapters serve all three modes.
4

Data durability by default

Every write goes through an atomic INSERT … ON CONFLICT … DO UPDATE … RETURNING statement, so state survives restarts and is always consistent — even when reads are load-balanced across async replicas.

Key features

16 Persist Adapters

Full coverage of the backtest-kit IPersist* contract: Candle, Signal, Strategy, Risk, Partial, Breakeven, Storage, Notification, Log, Measure, Interval, Memory, Recent, State, Session, Schedule.

Atomic Upserts

Single-statement ON CONFLICT … DO UPDATE … RETURNING eliminates read-then-write races and replica-lag surprises.

O(1) Redis Cache

Each domain has a cache service that stores only the row UUID in Redis, turning hot-path lookups from O(log n) B-tree scans into O(1) hash gets.

Pgpool-II Dev Cluster

A single container image runs 1 primary + 2 streaming replicas behind Pgpool-II, so replication-lag bugs surface in development — not in production.

Look-Ahead Bias Guard

Signal-affecting tables store a when bigint column with the logical simulation timestamp, enabling backtest-kit to prevent future-data leakage.

Zero Migration Overhead

TypeORM synchronize: true creates all tables and unique indexes automatically on first boot — no migration scripts needed.

Build docs developers (and LLMs) love