Deploying a Hyperswitch App
Introduction
Hyperswitch is an open-source payment orchestration platform built in Rust with a PostgreSQL and Redis backbone. Deploying Hyperswitch with a Dockerfile on Klutch.sh gives you reproducible builds, managed secrets, and HTTP/TCP routing for both API and webhook traffic—all from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, and best practices for secure, compliant payment flows.
Prerequisites
- A Klutch.sh account (create one)
- A GitHub repository with your Hyperswitch fork or configuration (GitHub is the only supported git source)
- Docker familiarity and Rust toolchain experience
- PostgreSQL credentials and Redis endpoint for caching/queues
- TLS certificate/key (optional) if you terminate TLS inside the container
For platform basics, review the Quick Start.
Architecture and ports
- Hyperswitch serves its API over HTTP; set the internal container port to
8080. - PostgreSQL and Redis should run as separate Klutch.sh TCP apps. Expose them on port
8000and connect internally on their native ports (5432for Postgres,6379for Redis). - Persistent storage is optional but recommended for configs, logs, and any custom SSL materials.
Repository layout
hyperswitch/├── config/ # app config, certs, secrets templates├── crates/ # Rust workspace crates├── docker/ # helper scripts (optional)├── Dockerfile # must be at repo root for auto-detection├── Cargo.toml├── Cargo.lock└── .env.example # template only; no secretsKeep secrets out of Git and store them as Klutch.sh environment variables.
Installation (local) and starter commands
Install dependencies and run locally before pushing to GitHub:
cargo build --releasecp config/config.example.toml config/config.tomlDATABASE_URL=postgres://user:pass@localhost:5432/hyperswitch \REDIS_URL=redis://localhost:6379 \ENCRYPTION_KEY=change-me-32-bytes \JWT_SECRET=change-me \./target/release/hyperswitchOptional helper start.sh for portability and Nixpacks fallback:
#!/usr/bin/env bashset -euo pipefail./target/release/hyperswitchMake it executable with chmod +x start.sh.
Dockerfile for Hyperswitch (production-ready)
Place this Dockerfile at the repository root; Klutch.sh auto-detects it (no Docker option in the UI):
FROM rust:1.72-slim AS buildWORKDIR /app
RUN apt-get update && apt-get install -y pkg-config libssl-dev clang && rm -rf /var/lib/apt/lists/*
COPY Cargo.toml Cargo.lock ./COPY crates ./cratesCOPY config ./configRUN cargo build --release
FROM debian:12-slimWORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates openssl && rm -rf /var/lib/apt/lists/*
COPY --from=build /app/target/release/hyperswitch /app/hyperswitchCOPY --from=build /app/config /app/config
ENV RUST_LOG=info PORT=8080
EXPOSE 8080CMD ["/app/hyperswitch"]Notes:
- Pin the Rust toolchain as needed for compliance or reproducibility.
- If you bundle TLS certs, mount them into
/app/config/certsand point your config there.
Environment variables (Klutch.sh)
Set these in the Klutch.sh app settings (Secrets tab) before deploying:
PORT=8080DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>REDIS_URL=redis://<user>:<password>@<host>:<port>ENCRYPTION_KEY=<32-byte-key>JWT_SECRET=<jwt-secret>RUST_LOG=infoAPP_BASE_URL=https://example-app.klutch.sh
If you deploy without a Dockerfile and want Nixpacks overrides:
NIXPACKS_BUILD_CMD=cargo build --releaseNIXPACKS_START_CMD=./target/release/hyperswitchNIXPACKS_GO_VERSION=1.21(omit for pure Rust; include only if you have Go helpers)NIXPACKS_RUST_VERSION=1.72
These ensure Hyperswitch builds and starts correctly when Nixpacks is used.
Attach persistent volumes (optional)
If you store TLS materials or custom configs on disk, add mount paths and sizes in Klutch.sh:
/app/config/certs— TLS keys and certificates./app/logs— optional log persistence if not shipping to an external sink.
Only mount path and size are required.
Deploy Hyperswitch on Klutch.sh (Dockerfile workflow)
- Push your repository (with the Dockerfile at the root) to GitHub.
- Open klutch.sh/app, create a project, and add an app.
- Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
- Choose HTTP traffic for the Hyperswitch API.
- Set the internal port to
8080. - Add the environment variables above (database, Redis, encryption, JWT, and any
NIXPACKS_*overrides if you temporarily deploy without the Dockerfile). - Attach persistent volumes for
/app/config/certsor/app/logsif you need them, choosing sizes that match your data requirements. - Deploy. Your API will be reachable at
https://example-app.klutch.sh; add custom domains as needed.
For PostgreSQL or Redis on Klutch.sh, create separate TCP apps, expose them on port 8000, and point DATABASE_URL or REDIS_URL to those endpoints (internal ports 5432/6379).
Health checks and production tips
- Add a
/healthendpoint that verifies DB and Redis connectivity. - Rotate
ENCRYPTION_KEYandJWT_SECRETcarefully to avoid invalidating tokens unintentionally. - Pin dependency versions and Rust toolchain for reproducible builds.
- Monitor database connections and Redis saturation; tune pool sizes accordingly.
- Back up databases regularly; do not rely on container filesystems for durability.
- Enforce HTTPS at the edge; terminate TLS before forwarding to
8080if desired.
Hyperswitch on Klutch.sh pairs reproducible Docker builds with managed secrets, optional persistent mounts, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and ports set to 8080 for the API (and 8000 externally for TCP databases or caches), you can orchestrate payments reliably without extra YAML or workflow overhead.