Sizing PostgreSQL for Hyperswitch: primary, replica and connections

Hyperswitch keeps its transactional state in PostgreSQL, so the database sets how many router pods you can run. This page explains how to size the primary, replica and connection pool, and how to run it on Kubernetes or as a managed service.

On this page

Sizing PostgreSQL for Hyperswitch: why the database sets your router ceiling

Before go-live, size PostgreSQL as a limit on router pods, not as an afterthought to compute. In a self-hosted Hyperswitch stack, the database, its connection limits and its replica layout often cap how many router pods you can run before CPU or memory does. The Hyperswitch architecture describes two application services, Router and Scheduler (Producer and Consumer), that both depend on PostgreSQL configured with a master and replica setup, and on Redis for caching and the scheduler queue. Because every additional router pod opens its own database connections, adding pods without checking the connection budget can make the database the bottleneck first.

PostgreSQL is released under the PostgreSQL License, a permissive open source license similar to the BSD and MIT licenses, so the database itself carries no license cost for your deployment. What you pay for is the engineering and operations around it: highly available primary and replica nodes, backups, and planned major upgrades. Confirm with your team which PostgreSQL major version you will deploy. Supported versions and their end-of-support dates are listed in the PostgreSQL versioning policy, and that date should drive your upgrade calendar from day one.

Ask three questions before you fix the database size. First, what is the maximum number of connections your router pods can open at peak, multiplied across every replica and the Scheduler? Second, does the replica serve read traffic from the application, and which queries go there? Third, what is your recovery target if the primary fails? Answers to these determine whether you need a connection pooler, how many replicas to run and whether you need automatic failover. Record the answers in your sizing document so the load test later checks the same assumptions.

PostgreSQL deployment options and when each fits

This table compares four ways to run the PostgreSQL primary and replica behind Hyperswitch: self-managed VMs or bare metal, CloudNativePG on Kubernetes, Patroni-managed clusters, and a managed cloud service. Read each row to see who runs failover, backups and upgrades, and what your team still owns. The main takeaway is that every option moves some work to a vendor or tool, but none removes the need to size connections, test restores and plan major version upgrades.

OptionWho runs failover, backups and upgradesWhat your team must still ownWhen it fits
Self-managed VM or bare metalYour team, using scripts or tools you choose; PostgreSQL does not detect primary failure on its ownReplication setup, failover tooling, WAL archiving, restore tests, major upgrades and OS patchingHosts already run in your data center and your DBAs run PostgreSQL today
PostgreSQL on Kubernetes with CloudNativePGThe operator handles failover through the Kubernetes API without Patroni, and manages backups and PostgreSQL versions it supportsKubernetes cluster health, storage classes, backup target configuration, restore drills and tracking operator releasesYour platform team already runs Kubernetes and wants the database managed as a cluster resource
Patroni-managed clusterPatroni handles leader election and failover, using ZooKeeper, etcd, Consul or Kubernetes as its configuration storeChoosing and operating the configuration store, backup tooling, upgrades of both Patroni and PostgreSQL, and failover testingYou want a proven HA layer on VMs or Kubernetes and accept running its distributed store yourself
Managed cloud PostgreSQL serviceThe cloud provider runs failover, backups and minor patching within the service's documented optionsInstance sizing, connection limits, parameter settings, major version timing, data retention and restore testingYour cloud account is the approved home for the database and the provider's controls meet your review
Connection and pooling responsibilityOperator-based and managed options may include pooling; VM and Patroni setups usually add PgBouncer yourselfPool sizing against router pod count, and confirming pooling mode works with your Hyperswitch configurationConfirm the pooling option and its limits in writing before you size router replicas

Primary and replica choices: synchronous, asynchronous and read traffic

With synchronous replication, PostgreSQL does not report a commit as successful until the configured standbys confirm they have received it. For a payment switch, this means a committed state change, such as a payment status or a refund record, is less likely to be lost if the primary fails right after acknowledging it. The cost is latency: every write waits for a network round trip to the standby, and a slow or unreachable standby slows or blocks commits, depending on how the standby set is configured.

  • Data loss exposure: Confirmed commits exist on at least one standby before the application sees success, which narrows the window for lost payment state.
  • Write latency: Each commit adds a round trip to the standby, so placement of the replica in the same region or availability zone matters.
  • Availability trade-off: If required standbys are down, writes can stall. Ask how the configuration behaves when no standby acknowledges.
  • Quorum settings: Operators such as CloudNativePG support quorum-based synchronous replication, which reduces the effect of one standby failing.
  • Scope: Synchronous settings are a database decision. Confirm with Hyperswitch which tables must survive a failover without loss before choosing.

Before committing to this mode, load test the write path with your planned standby placement and confirm the failure behavior with your team.

Setup sequence for PostgreSQL behind Hyperswitch

This sequence takes PostgreSQL from version selection to a tested restore, so the database behind Hyperswitch has a primary, a replica, controlled connections and recoverable backups before the router pods depend on it.

  1. Choose the PostgreSQL major version

    Before provisioning anything, the platform team checks the PostgreSQL support windows and picks a major version that will still be supported for the expected life of the deployment. PostgreSQL 18 is supported until November 14, 2030, while PostgreSQL 14 is supported only until November 12, 2026, so a new build should not start on 14. Confirm the version your Hyperswitch release and your chosen operator or managed service support, since compatibility is not implied by the database version alone. The step is done when the version and its end-of-support date are written into the design record and approved by the database owner.

  2. Provision the primary and the replica

    The infrastructure team creates one primary and at least one hot standby in separate failure domains, sized for storage growth and the connection budget agreed in the capacity plan. The replica serves read-only queries, so the Hyperswitch configuration must point read traffic at it explicitly, and the team must confirm that the application's read path is designed for that. Check the result by connecting to the standby and confirming it reports that it is in recovery and accepts read-only queries.

  3. Set SCRAM authentication and restrict access

    Set the password encryption method to SCRAM and disable MD5 password authentication in the host-based access rules, so only the Hyperswitch database roles can connect from the router and scheduler network ranges. PostgreSQL 18 deprecates MD5 in favor of SCRAM, so older authentication settings carried over from a template should be removed rather than left as fallbacks. Decide whether a certificate or external method is needed for administrative access, and confirm each method against the client authentication documentation. The check is a connection attempt from an unlisted host that is refused, and a login from an allowed pod that succeeds with a SCRAM password.

  4. Configure the replication mode

    Choose between synchronous replication, where a commit waits for the standby, and asynchronous replication, where it does not. Synchronous replication protects committed payment state at the cost of write latency and availability when the standby is unreachable, so the decision belongs to the payments and risk owners as well as the database team. PostgreSQL does not detect a primary failure on its own, so decide whether an operator or external tooling will handle promotion before go-live. The step is complete when the replication mode is set, the standby is streaming, and a test write on the primary appears on the standby.

  5. Add connection pooling in front of the database

    Place a connection pooler such as PgBouncer between the Hyperswitch services and PostgreSQL so that many pods do not each open a full set of server connections. The pool size, the number of pods allowed to connect, and the server connection limit must be set together, because the database connection ceiling caps how many router pods can run. Confirm with the Hyperswitch configuration documentation which pooling mode is supported, and test pool behavior under the planned pod count. The check is that connected client counts stay within the pool limit during a load run and that the pooler reports no waiting clients at the expected peak.

  6. Enable WAL archiving and point-in-time recovery

    Turn on continuous archiving so that write-ahead log segments are shipped to durable storage outside the database hosts, and take a base backup on a schedule the team can explain to auditors. Point-in-time recovery depends on both the base backups and the archived logs, so a missing segment breaks the recovery window, and the archive destination needs its own retention, access control and monitoring. Confirm the archive command reports success and that archived segments and base backups are listed in the backup inventory. The step is done when the archive is current and an alert fires if archiving stops.

  7. Run a restore test to a recovery point

    Restore the latest base backup and replay archived logs to a chosen time in a separate environment, then start a Hyperswitch router against the restored database to confirm the application reads consistent data. Record how long the restore took, which steps were manual, and what the recovery point and data loss window were, because those numbers should come from your own run, not from an estimate. Repeat the test after major configuration changes or upgrades. The step is complete when the restored database passes the application's read checks and the results are filed with the runbook.

Planning storage growth and backup retention

Storage sizing for the Hyperswitch database has to cover more than the live data set. Payment records, attempt history, events and audit-style rows accumulate with every transaction, and the database also holds write-ahead log (WAL) files, backup copies and the storage for each replica. Size the volume for the sum of those components over your retention window, not for today's table sizes. No growth rate is supplied for Hyperswitch, so measure it yourself: run a representative load test or capture a few weeks of production writes, then record how much the primary database grows per thousand transactions and how much WAL it generates at peak. Ask Juspay and your Hyperswitch deployment team which tables grow fastest on your version so you can watch them specifically.

Retention is a compliance decision before it is a storage decision. Agree with your compliance owners, and with your payments and legal teams, how long transaction records, logs and backups must be kept, and when card-related data must be deleted. Hyperswitch runs scheduled tasks for some of this clean-up, so confirm with your team how those jobs interact with the retention rules you set. Backups must follow the same schedule. Keeping backups longer than the data they protect creates a second copy that the deletion policy has to reach.

For recovery, the baseline PostgreSQL mechanism is continuous archiving: a base backup plus archived WAL segments, which lets you restore to a chosen point in time. On Kubernetes, CloudNativePG can write base backups and WAL to object storage through the Barman Cloud plugin, take volume snapshot backups, and restore point-in-time from archived WAL. Plan the object storage bucket, its lifecycle and encryption, and the retention policy in the operator's backup configuration together, and confirm the exact configuration keys against the version you deploy. Restore tests should run at the same cadence as backups, and the restore time you measure becomes part of your recovery objective.

Securing the database layer

The PostgreSQL database holds the transactional state behind every router and scheduler pod, so its access controls matter as much as its sizing. The cards below cover how clients authenticate, which workloads can reach the database, how backups and logs are protected, and where card data should not live at all. Treat each item as something to confirm in your own environment, because the merchant remains responsible for data handling in a self-hosted deployment.

Choose the authentication method

PostgreSQL supports password, certificate, GSSAPI, LDAP and OAuth client authentication, and it deprecated MD5 password authentication in favor of SCRAM in PostgreSQL 18. Use SCRAM at minimum for the Hyperswitch database roles, and check whether your platform team can issue client certificates or OAuth tokens to the router and scheduler pods. Confirm which method your chosen operator or managed service exposes before you write the pg_hba.conf rules.

PostgreSQL auth methods

Restrict network reach to Hyperswitch pods

Only the Router and Scheduler workloads need a route to the primary and replicas, so limit it with Kubernetes network policies, security groups or firewall rules. Keep administrative sessions on a separate bastion path and block direct access from the wider network. Confirm that the Redis, monitoring and batch tools your team runs do not share a broad allow rule with the database.

Use separate roles per service

Give the router, the scheduler and any migration or reporting job their own database roles with the minimum privileges they need. A separate read-only role for replica reporting limits what a leaked credential can do. Store passwords in your secrets manager and rotate them on a schedule you can document, and confirm that the Hyperswitch Helm values reference those secrets rather than inline values.

Encrypt backups and WAL archives

Base backups and WAL archives contain the full transactional record, so they need the same protection as the live database. Encrypt them at rest in object storage or snapshots, restrict who can read or restore them, and test a point-in-time restore into an isolated environment. Ask your operator or backup tool how keys are managed and where they are kept, separate from the backup bucket.

Log connections and privileged activity

Enable connection and disconnection logging and log statements from privileged roles, then send those logs to a store your security team controls. Review failed authentication attempts and unexpected role changes as part of normal operations. Confirm the log volume and retention you need before you enable verbose statement logging, because it can grow quickly on a busy payment path.

Keep card data out of the transactional database

Hyperswitch stores card data in its card vault (locker), a separate Rust service, so the PostgreSQL database should hold tokens and payment state rather than primary account numbers. Confirm this separation in your deployment by checking which tables and services receive raw card fields. Because the in-house vault model makes the merchant fully responsible for PCI DSS certification and data handling, an outsourced vault model may change which systems fall into scope. Confirm the scope decision with your assessor before go-live.

In-house PCI vault model

Every router and scheduler write passes through one primary, with the replica and WAL archive kept inside the database boundary

The diagram starts with Router pods and the Scheduler producer and consumer, which both reach PostgreSQL through a connection pooler. The pooler is the point to check first, because every pod's connections are multiplied against the primary's connection limit. Redis sits beside the application path for caching and the scheduler queue, so it is not a database dependency. Inside the trust boundary, the PostgreSQL primary streams WAL to a streaming replica and archives WAL to object storage, which is the backup target you must secure and restore-test. Confirm which connections the replica serves and how failover is triggered.

Router and scheduler traffic reaches the primary through a pooler, with replica and WAL archive inside the boundary.

Limits to confirm in your environment

The sizing choices on this page depend on values that change between Hyperswitch releases, PostgreSQL versions, failover tooling and hosting platforms. Check each item below in your own environment before you commit to a connection budget, a replica design or a recovery target.

Connection settings per release

The number of connections each router and scheduler pod opens depends on the pool settings in the Hyperswitch release you deploy, and those settings can change between minor releases. Read the configuration for your exact version and multiply the pool size by your planned pod count, then add connections for the scheduler, migrations and admin sessions. Compare that total with the connection limit your database actually enforces, not the default value. Confirm the figure in a staging load test before go-live.

Self-hosting docs

PostgreSQL version support

Your Hyperswitch release supports a specific set of PostgreSQL major versions, and that list is the first constraint on your upgrade plan. Match it against the PostgreSQL community support calendar, where version 14 reaches end of support in November 2026 and version 18 is supported until November 14, 2030. Check the release notes for your Hyperswitch version before choosing a target, because a database that is still supported by PostgreSQL may still be outside the list that Hyperswitch tests against.

PostgreSQL versioning policy

Failover tool behavior in your cluster

PostgreSQL does not detect a failed primary or promote a standby on its own, so the failover tool you choose defines how long writes stop during an incident. Test promotion, fencing of the old primary and the reconnect path from Hyperswitch in your own network, including DNS or service endpoint changes. Record how long the router pods take to reach the new primary, and whether any pod keeps writing to the old one. Treat vendor behavior as a claim to verify, not a guarantee.

PostgreSQL failover docs

Backup restore time

A backup is only useful if the restore finishes inside the time your payment operation can tolerate. Restore a recent base backup and replay archived WAL to a point in time in a separate environment, then time each step, including object storage download, data directory preparation and replay. Repeat the test as the database grows, because restore time scales with data volume and WAL volume. Record the measured figure as your recovery target, not the figure you hoped for.

Continuous archiving docs

Replica lag tolerance

Reads sent to a hot standby can return data that is behind the primary, and the acceptable delay depends on which Hyperswitch paths use the replica. Decide which reads may tolerate lag, such as reporting or some lookups, and which must read from the primary, such as anything tied to a payment state change. Measure replay lag under peak write load, and set alerts for values above the limit you choose. Synchronous replication removes that lag at the cost of commit latency, so confirm the trade-off with your own test results.

Managed service vendor limits

If you run PostgreSQL as a managed service, the provider sets limits on connections, storage growth, IOPS, backup retention, replica count and maintenance windows, and those limits differ by plan and region. Ask the provider for the exact values for your instance class and confirm whether its pooler, failover and point-in-time recovery meet the requirements in this page. Check how upgrades to a new major version are scheduled, and whether the provider permits the extensions and authentication methods your Hyperswitch setup needs.

PostgreSQL sizing questions buyers ask before hiring help

What drives the cost of a PostgreSQL build for Hyperswitch?

The cost follows the amount of design, build and testing work, which depends on how many environments you run, whether you need replicas and failover, and how much backup and recovery verification you want. The main components are discovery of your transaction and connection profile, the topology design (primary, replica, pooling), the deployment itself, backup and point-in-time recovery setup, and a restore test. Most of this is one-time work, while patching, monitoring, backup checks and minor-version updates recur. Ask for a quote that lists each component separately, states which environments are covered, and says who runs the recurring tasks after handover. DeployOpen does not publish prices, so the quote is built from the written scope.

Can our team size a Hyperswitch PostgreSQL database alone?

Yes, if you have engineers who have run PostgreSQL in production and you can supply real traffic data. Sizing needs the write rate from payments, scheduler activity, the number of router pods that will connect, and the connection limits each pod opens, all of which must be measured or forecast. The harder parts are usually failover design, connection pooling with PgBouncer, and proving that a restore works. A team with no PostgreSQL operations experience will spend most of its effort learning these areas. An outside review can check your sizing assumptions before go-live, and that review is often cheaper than a production incident.

How long does a PostgreSQL build for Hyperswitch take?

The duration depends on the scope and on how quickly your team can provide inputs, not on a fixed number of days. Work usually moves through traffic and compliance discovery, topology design, a build in staging, load testing against the sizing, backup and restore testing, and then go-live. Delays most often come from missing traffic forecasts, unclear retention rules, change approval windows, and network or storage approvals in your own environment. Ask the provider for a timeline tied to named milestones and to the inputs you must supply, and confirm which of those dependencies sit with your team.

What must our team provide before a PostgreSQL sizing engagement starts?

Your team needs to supply the data that sizing depends on. The main inputs are:

  • Historical and forecast transaction volume, including peak periods and retry behavior
  • Router pod counts, connection settings and the number of Scheduler consumers planned
  • Storage growth expectations and data retention periods for payment records
  • Compliance requirements, such as where backups may be stored and who may access them
  • Access to your metrics platform, cloud or cluster accounts, and change windows

If you cannot supply forecasts, say so in the scope. The engagement can then include a measurement phase, which should be written into the quote with its own deliverables.

Is running PostgreSQL managed or on Kubernetes cheaper for Hyperswitch?

Neither option is cheaper in general, because the costs sit in different places. A managed service moves patching, hardware replacement and some failover tasks to the provider, but it charges for instance size, storage, backup retention and replicas, and it limits the extensions and parameters you can change. Self-managing on Kubernetes avoids that service fee, but your team pays for operator administration, storage classes, backup tooling and on-call work. The CloudNativePG operator handles failover through the Kubernetes API and manages persistent volume claims directly, which reduces some of that work. Compare both options using the same sizing, the same replica count and the same backup retention, then include staff time.

How are PostgreSQL major upgrades done for a live Hyperswitch database?

A major upgrade is done with one of three methods: a dump and restore with pg_dumpall, pg_upgrade, or logical replication. Logical replication works across major versions and can keep downtime to several seconds, but it needs careful checks of sequences, replicated objects and the cutover sequence. The PostgreSQL 18 release retains planner statistics during pg_upgrade and adds parallel jobs and a --swap option, which shorten some steps. Before choosing a method, confirm the version lifecycle: version 14 is supported until November 12, 2026, so plan the move before that date. Ask for a rehearsal on a copy of production and a written rollback plan.

When should we bring in outside help for Hyperswitch PostgreSQL?

Bring in help when the database will carry live payment traffic and your team lacks recent experience with replication, failover, connection pooling or restore testing. Outside help is also worth considering when you need evidence for a compliance review, such as documented backup restores and access controls. Good reasons to wait are a stable, already-tested setup that your team runs well. Whatever you decide, ask any provider to show how they would test a failover and a point-in-time restore, and to confirm that the database stays within your own cloud accounts or data centers. Review the written scope before agreeing to it.

How DeployOpen scopes PostgreSQL sizing for Hyperswitch

DeployOpen plans, implements, hardens, backs up, upgrades, documents and supports self-hosted open-source platforms inside infrastructure the client controls, including PostgreSQL for Hyperswitch. Most engagements are fixed-scope, so the database work is defined in writing before anything is built: which PostgreSQL major version is targeted, whether replication runs as a primary with a hot standby or in a Kubernetes operator, how the connection pool sits in front of the database, which backup method and recovery targets apply, and who owns the storage growth forecast after go-live. Scope also states the environments covered, the cloud or data center accounts involved, and the handover documents the client receives.

Deliverables should name the artifacts you will actually inspect: the sizing worksheet tying router pod counts to maximum database connections, the replication and failover design, backup and restore test records, and the runbook for major upgrades. Ask the partner to state which of these depend on your decisions and which depend on a test you run. Compliance support follows the same pattern. DeployOpen prepares systems, controls and evidence for compliance assessments, such as configuration records, access settings and backup logs, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies do that work, so ask early which evidence your assessor expects.

A quote follows from the written scope, not from a published price list. To compare proposals, ask each partner to itemize the discovery and sizing work, build and configuration, load and failover testing, backup and restore verification, documentation, and any ongoing support or retainer. Confirm which items are one-time and which recur, such as patching PostgreSQL minor releases and monitoring storage. Cost rises with the number of environments, the number of replicas, the automation required and the number of tests the scope includes. Confirm these assumptions in the proposal so the quote and the implementation stay aligned.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.