Skip to content

Maintenance & CLI

To maintain peak performance, the outbox table must be periodically cleaned. The Open Outbox Relay includes a built-in CLI designed for maintenance, cleanup, and manual intervention.

Open Outbox is designed to handle tables with thousands of records efficiently using standard indexes. However, regular maintenance is required to keep indexes lean and prevent database bloat.

While the Relay handles high-volume workloads, if your dataset grows into the hundreds of millions or billions of records, standard DELETE operations will eventually become a bottleneck.

At this scale, we recommend implementing Table Partitioning (e.g., by date) at the database level. This allows you to manage data by dropping old partitions rather than executing row-by-row deletions. Note that partition rotation must be managed externally, as Open Outbox does not natively manage database partitions.

Successfully delivered or exhausted (dead) events should be removed periodically to maintain query speed.

You can prune events based on their age and status:

  • Delivered Events: Successfully processed messages.
  • Dead Events: Messages that have exhausted all retry attempts.

The maintenance CLI is bundled within the standard Relay image. To use it with Docker Compose, you must first define a cli service in your docker-compose.yaml with the correct entrypoint and profile.

services:
# Main Relay Service
relay:
image: openoutbox/relay:latest
# ... other config
# Maintenance CLI Service
cli:
image: openoutbox/relay:latest
entrypoint: ["/app/cli"]
environment:
- STORAGE_TYPE=postgres
- STORAGE_URL=postgres://user:pass@db-host:5432/db
profiles: ["tools"] # Prevents the CLI from starting with 'up'

Once configured, use the docker compose run command to invoke the pruning tool.

Dry Run (Simulation): Verify the impact before deleting data

Terminal window
docker compose run --rm cli prune --delivered-age 7d --dead-age 30d --dry-run

Execute Pruning: Remove successfully delivered events older than 7 days and dead events older than 30 days.

Terminal window
docker compose run --rm cli prune --delivered-age 7d --dead-age 30d

For production environments, automate maintenance using a system crontab.

Terminal window
# Run daily at 2:00 AM
0 2 * * * cd /path/to/project && docker compose run --rm -T cli prune --delivered-age 7d --dead-age 30d