Skip to content
STACK IT FAST

Hyperswitch

Curated OSSClassicOpen-Source Payments Orchestration20+ people

Audited from github.com/juspay/hyperswitch

Hyperswitch is an open-source, composable payments platform by Juspay, written in Rust, that connects many payment processors behind one API with routing, retries, vaulting, reconciliation and cost observability.

Language
Rust
Database
PostgreSQL
Hosting
Docker
License
Apache-2.0
Running for
3 years
Team
20+ people

Why this architecture

Hyperswitch runs a panic-averse Rust router on Actix Web with Redis absorbing hot writes and a drainer persisting them to PostgreSQL, while a routing DSL that also compiles to WebAssembly keeps processor selection consistent between server and browser.

Tech stack by layer

14 technologies · audited Oct 2, 2026
Backend & APIs
  • RustLanguage for the router, drainer, scheduler and all crates/ members; the workspace forbids unsafe code.
  • Actix-webHTTP framework used across the API crates, analytics and the drainer service.
  • EuclidIn-house DSL for static payment routing, with macros, a constraint graph and WebAssembly bindings for browsers.
  • utoipaOpenAPI generation for request and response models; validate-openapi-spec.yml checks the published spec.
  • Smithysmithy, smithy-core and smithy-generator crates derive Smithy models from shared enums and types.
Data & Persistence
  • PostgreSQLPrimary store for payments, attempts, mandates and merchants, with Diesel migrations since 2022.
  • DieselORM with async-bb8-diesel pooling and 128-column tables, shared through the diesel_models crate.
  • RedisKV store and streams; the drainer reads Redis streams and writes the queries to PostgreSQL.
  • OpenSearchSearch backend in the analytics crate, with AWS auth support; analytics also queries Postgres through sqlx.
Infrastructure & Deploy
  • DockerDockerfile builds router or other binaries per profile; docker-compose.yml runs Postgres, Redis and a migration runner.
  • GrafanaObservability configs for Grafana, Loki, Promtail, Tempo, Prometheus, Vector and an OpenTelemetry collector.
  • CypressEnd-to-end payment, payout and routing suites in cypress-tests and cypress-tests-v2, plus Postman collections via newman.
  • k6Load tests in loadtest/ with their own docker-compose and Grafana setup.
  • Nixflake.nix provides a development shell, checked by nix.yaml.

Hyperswitch architecture diagram

Open SVG
Hyperswitch architecture diagramMerchant backend → router (payments API); Browser tools → router; router → KV and streams (kv writes); router → Payments DB (Diesel); router → Payment processors (authorize); drainer → KV and streams (read streams); drainer → Payments DB (persist); scheduler → router (retries); router → Analytics search (analytics)CLIENTSSERVICESWORKERS & JOBSDATA & STORAGEEXTERNALMerchant backendREST APIBrowser toolsEuclid WASMrouterRust · Actix WebdrainerRedis streams → DBschedulerRustKV and streamsRedisPayments DBPostgreSQL · DieselAnalytics searchOpenSearchPayment processorsconnectorspayments APIread streamspersistretrieskv writesDieselanalyticsauthorize
How the main components of Hyperswitch connect, drawn from the audited repository.
Diagram as text
  • Merchant backend (REST API) → router (Rust · Actix Web): payments API
  • Browser tools (Euclid WASM) → router (Rust · Actix Web)
  • router (Rust · Actix Web) → KV and streams (Redis): kv writes
  • router (Rust · Actix Web) → Payments DB (PostgreSQL · Diesel): Diesel
  • router (Rust · Actix Web) → Payment processors (connectors): authorize
  • drainer (Redis streams → DB) → KV and streams (Redis): read streams
  • drainer (Redis streams → DB) → Payments DB (PostgreSQL · Diesel): persist
  • scheduler (Rust) → router (Rust · Actix Web): retries
  • router (Rust · Actix Web) → Analytics search (OpenSearch): analytics

Key architectural decisions

5 decisions
  1. 01

    Strict panic-free lint policy across the workspace

    The root Cargo.toml forbids unsafe_code and warns on unwrap_used, expect_used, panic, indexing_slicing, as_conversions, print_stdout and more, and the Makefile runs clippy with -D warnings, so payment code paths are pushed towards explicit error handling with error-stack.

  2. 02

    Redis in front of Postgres, drained asynchronously

    diesel_models has a default kv_store feature, and crates/drainer is described as an "application that reads Redis streams and executes queries in database", so hot payment writes land in Redis first and a separate drainer persists them to PostgreSQL.

  3. 03

    A routing DSL compiled to native and WebAssembly

    crates/euclid is a "DSL for static routing" with euclid_macros and hyperswitch_constraint_graph, and crates/euclid_wasm exposes it as a WebAssembly JavaScript library via wasm-bindgen (make euclid-wasm), so routing rules can be checked in the browser with the same code the server runs.

  4. 04

    v1 and v2 APIs as compile-time feature sets

    Crates expose v1 and v2 features (for example in api_models, diesel_models and analytics), the Dockerfile selects VERSION_FEATURE_SET at build time, and separate diesel.toml / diesel_v2.toml files and api-migrations-compatibility.yml keep both schemas in check.

  5. 05

    Connectors as templated modules

    connector-template/ (mod.rs, transformers.rs, test.rs) and add_connector.md define how a new payment processor is added to crates/hyperswitch_connectors, so each integration follows the same request/response transformer structure.

How Hyperswitch is built

How Hyperswitch is structured

Hyperswitch is a Cargo workspace (members = ["crates/*"], edition 2021, Rust 1.85) with a crate for each concern:

Crates Role
router, router_derive, router_env The main payments API service, its derive macros and logging/metrics environment
api_models, diesel_models, hyperswitch_domain_models, common_* API, database and domain types shared across services
hyperswitch_connectors, connector_configs, hyperswitch_interfaces Payment processor integrations and their configuration
drainer, scheduler Background services: Redis-stream-to-Postgres drainer and scheduled jobs
euclid, euclid_macros, euclid_wasm, hyperswitch_constraint_graph, kgraph_utils Routing DSL and its constraint graph, also compiled to WebAssembly
analytics, events, currency_conversion Reporting, search, event publishing, cost-based routing
payment_methods, pm_auth, cards, card_metadata, payment_link, subscriptions Payment method handling, card types with masking, payment links
redis_interface, storage_impl, external_services Storage and external service adapters (KMS and others)
smithy, smithy-core, smithy-generator, openapi Smithy models and the OpenAPI spec

Other top-level directories: api-reference/ (MDX API docs with v1 and v2 specs), config/ (TOML configs plus Grafana, Loki, Tempo, Prometheus, Vector and OTel collector configs), cypress-tests/ and cypress-tests-v2/, loadtest/ (k6), migrations/, docker/, docs/rfcs.

Backend & APIs

The services run on Actix Web. Errors use error-stack throughout, and hyperswitch_masking wraps sensitive values such as card data so they are not logged by accident (crates/cards). Request and response models in api_models derive OpenAPI schemas with utoipa, and validate-openapi-spec.yml checks the generated spec in CI.

Routing is a language of its own. crates/euclid defines a DSL for static routing on top of hyperswitch_constraint_graph, with an optional nom parser. crates/euclid_wasm builds it with wasm-bindgen (make euclid-wasm) as a JavaScript library, so routing rules can be evaluated in the browser with the server's own code. currency_conversion supports cost-based routing.

Data & persistence

PostgreSQL holds the core payment records, accessed with Diesel 2 and async-bb8-diesel pools (crates/diesel_models). Migrations in migrations/ start in 2022, and diesel.toml and diesel_v2.toml cover the two API generations. Redis is both cache and write buffer: diesel_models enables a kv_store feature by default, and crates/drainer reads Redis streams and executes the queued queries against Postgres. redis_interface supports both fred and redis-rs clients. Analytics query Postgres with sqlx and search with OpenSearch (crates/analytics).

Build, test & deploy

  • The Dockerfile builds a chosen binary (BINARY=router by default) with a CARGO_BUILD_PROFILE of release, release-fast or dev, and a VERSION_FEATURE_SET of v1 or v2. docker/ adds images for the web build, WASM builds and the migration runner.
  • docker-compose.yml starts PostgreSQL, Redis and a migration runner that installs diesel_cli and runs just migrate. docker-compose-development.yml covers local development.
  • CI workflows include CI-pr.yml, CI-push.yml, migration-check.yaml, api-migrations-compatibility.yml, cypress-tests-runner.yml, postman-collection-runner.yml, validate-openapi-spec.yml, wasm-bulild-check.yml and nightly and stable release workflows, plus hotfix branch automation.
  • Tests: Rust tests with nextest (.github/nextest.toml), Cypress end-to-end suites for payments, payouts and routing, Postman collections run with newman, and k6 load tests in loadtest/.

Self-hosting notes

The quickest path is docker-compose.yml with the configs in config/docker_compose.toml. docs/one_click_setup.md, docs/try_local_system.md and docs/building_docker_images.md walk through local and image-based setups. config/ ships ready-made Grafana, Loki, Promtail, Tempo, Prometheus and OpenTelemetry collector configs for a full observability stack.

What to copy (and what not to)

Copy:

  • Clippy as policy. Warning on unwrap_used, panic, indexing_slicing and as_conversions workspace-wide is a cheap way to keep panics out of money-moving code.
  • Share logic between server and browser by compiling a domain crate to WebAssembly (Euclid).
  • A connector template so dozens of third-party integrations look the same.
  • OpenAPI validation and migration-compatibility checks in CI for a public API.

Don't copy blindly:

  • A Redis write buffer with an asynchronous drainer improves latency but adds a consistency window and another service to operate. It suits high-volume payment traffic, not a typical CRUD app.
  • Maintaining v1 and v2 as compile-time feature sets doubles the build and test matrix.

For the Actix Web framework itself, see Actix Web.

Sources & repo audit

Audited
Oct 2, 2026
Commit
d03f854
License
Apache-2.0

Independent analysis of repository at github.com/juspay/hyperswitch. Spotted an inaccuracy? Use the claim form to request a correction.

Maintainer? Add the architecture badge to your README
architecture: stackitfast
[![Architecture on STACK IT FAST](https://stackitfast.com/badge/hyperswitch.svg)](https://stackitfast.com/project/hyperswitch)
Use this stack

Scaffold it with your agent

Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Hyperswitch's architecture.

  1. 1Copy the promptThe full markdown spec, with every layer and decision.
  2. 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
  3. 3Paste and scaffoldUse it as the first instruction; review before you ship.
use-this-stack.md · 58 lines · 7.3 KB
# MISSION: Scaffold "Hyperswitch" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Hyperswitch**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Hyperswitch
- **What It Does**: Hyperswitch is an open-source, composable payments platform by Juspay, written in Rust, that connects many payment processors behind one API with routing, retries, vaulting, reconciliation and cost observability.
- **Domain & Category**: Open-Source Payments Orchestration
- **Production Scale**: 20+ people
- **Development Mode**: CLASSIC
- **Architectural Rationale**: Hyperswitch runs a panic-averse Rust router on Actix Web with Redis absorbing hot writes and a drainer persisting them to PostgreSQL, while a routing DSL that also compiles to WebAssembly keeps processor selection consistent between server and browser.
- **Live Website Reference**: https://hyperswitch.io
- **Source Repository**: https://github.com/juspay/hyperswitch
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: Rust, Actix-web, Diesel, PostgreSQL, Redis, sqlx, OpenSearch, WebAssembly, Docker, Grafana, Prometheus, OpenTelemetry, Cypress, Nix
- **Primary Language(s)**: Rust, JavaScript, MDX, Shell
- **License of the reference repo**: Apache-2.0
- **Backend & APIs**: Rust — Language for the router, drainer, scheduler and all crates/ members; the workspace forbids unsafe code.; Actix-web — HTTP framework used across the API crates, analytics and the drainer service.; Euclid — In-house DSL for static payment routing, with macros, a constraint graph and WebAssembly bindings for browsers.; utoipa — OpenAPI generation for request and response models; validate-openapi-spec.yml checks the published spec.; Smithy — smithy, smithy-core and smithy-generator crates derive Smithy models from shared enums and types.
- **Data & persistence**: PostgreSQL — Primary store for payments, attempts, mandates and merchants, with Diesel migrations since 2022.; Diesel — ORM with async-bb8-diesel pooling and 128-column tables, shared through the diesel_models crate.; Redis — KV store and streams; the drainer reads Redis streams and writes the queries to PostgreSQL.; OpenSearch — Search backend in the analytics crate, with AWS auth support; analytics also queries Postgres through sqlx.
- **Infrastructure & deploy**: Docker — Dockerfile builds router or other binaries per profile; docker-compose.yml runs Postgres, Redis and a migration runner.; Grafana — Observability configs for Grafana, Loki, Promtail, Tempo, Prometheus, Vector and an OpenTelemetry collector.; Cypress — End-to-end payment, payout and routing suites in cypress-tests and cypress-tests-v2, plus Postman collections via newman.; k6 — Load tests in loadtest/ with their own docker-compose and Grafana setup.; Nix — flake.nix provides a development shell, checked by nix.yaml.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/juspay/hyperswitch @ d03f854)
1. **Strict panic-free lint policy across the workspace**: The root Cargo.toml forbids unsafe_code and warns on unwrap_used, expect_used, panic, indexing_slicing, as_conversions, print_stdout and more, and the Makefile runs clippy with -D warnings, so payment code paths are pushed towards explicit error handling with error-stack.
2. **Redis in front of Postgres, drained asynchronously**: diesel_models has a default kv_store feature, and crates/drainer is described as an "application that reads Redis streams and executes queries in database", so hot payment writes land in Redis first and a separate drainer persists them to PostgreSQL.
3. **A routing DSL compiled to native and WebAssembly**: crates/euclid is a "DSL for static routing" with euclid_macros and hyperswitch_constraint_graph, and crates/euclid_wasm exposes it as a WebAssembly JavaScript library via wasm-bindgen (make euclid-wasm), so routing rules can be checked in the browser with the same code the server runs.
4. **v1 and v2 APIs as compile-time feature sets**: Crates expose v1 and v2 features (for example in api_models, diesel_models and analytics), the Dockerfile selects VERSION_FEATURE_SET at build time, and separate diesel.toml / diesel_v2.toml files and api-migrations-compatibility.yml keep both schemas in check.
5. **Connectors as templated modules**: connector-template/ (mod.rs, transformers.rs, test.rs) and add_connector.md define how a new payment processor is added to crates/hyperswitch_connectors, so each integration follows the same request/response transformer structure.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
   - Structure as a Turborepo monorepo with strict package boundaries:
     - `apps/web`: Application UI, routing, layouts, and server endpoints.
     - `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
     - `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
     - `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
   - Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
   - Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
   - Isolate interactive UI state to leaf components. Keep core pages lightweight and performant.
4. **Design System & Aesthetics**:
   - Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
   - Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
   - Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
   - Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (PostgreSQL, Diesel, Redis, OpenSearch): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.
Scaffolded something with this prompt?
Would you pick this stack for a open-source payments orchestration project?

Frequently asked about Hyperswitch

What is Hyperswitch built with?

Hyperswitch is written in Rust with Actix Web, Diesel on PostgreSQL and Redis. A drainer service moves writes from Redis streams into Postgres, analytics use OpenSearch and sqlx, and the Euclid routing DSL also compiles to WebAssembly for use in the browser.

Can I self-host Hyperswitch?

Yes. The repository has a docker-compose.yml that starts PostgreSQL, Redis and a Diesel migration runner alongside the services, plus docs such as docs/one_click_setup.md and docs/try_local_system.md, and configs under config/ for development and Docker Compose.

Does Hyperswitch use Actix or Axum?

Actix Web. The api_models, analytics and drainer crates depend on actix-web, and the README badge describes the project as made in Rust.

How does Hyperswitch route payments?

Static routing rules are written in Euclid, an in-house DSL in crates/euclid backed by a constraint graph. The same DSL compiles to WebAssembly (crates/euclid_wasm) so routing rules can be validated in the browser.

How are payment connectors added?

New processors follow connector-template/ (mod.rs, transformers.rs and test.rs) and the add_connector.md guide, and live in crates/hyperswitch_connectors alongside connector configuration in crates/connector_configs.

One email a month: new deep dives and stack trends

New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.

use-this-stack.md