Home→About→Services→Products→Projects→Blog→Contact→
Infrastructure7 min read

Database failover automation for Sri Lanka data centers: cutting latency to under 30 seconds

We walk through how to build automated failover for production databases running in Sri Lanka. Real metrics: 28-second recovery time, 99.95% uptime.

PublishedNov 29, 2026
Reading time7 min
CategoryInfrastructure

When a database node fails at 2 a.m. on a Tuesday, the clock starts ticking. We work with retail and logistics teams across South Asia, and we have watched manual failover routines consume 12 to 18 minutes per incident. For a business processing 50 orders per minute, that is 600 to 900 orders stuck in a queue. Database failover automation for Sri Lanka data centers cuts that recovery window from minutes to seconds, and we want to show you exactly how we do it and what numbers matter.

Over the past five years, our team has deployed production databases in Colombo, Bangalore, and Jakarta. We have learned that failover is not optional infrastructure. It is the difference between a blip your customers never notice and a support ticket storm that hits your operations channel. In this post, we cover the three failover architectures we have tested, the hardware and software that work in the South Asian region, and the specific monitoring setup that caught failures before they became outages.

Why manual failover costs you 15 minutes per incident

Manual failover looks simple on a diagram. Database primary fails. Someone gets paged. Someone logs into a backup server, runs a promotion script, and updates the application connection string. In practice, this takes time. We tracked five production incidents across three clients in 2024 and 2025. Average detection time was 3 to 4 minutes. Average remediation time was 11 to 14 minutes. Total window: 15 minutes. For a typical SME processing 50 to 200 transactions per minute, that is 750 to 3,000 blocked operations.

The cost compounds. Every minute of downtime is not just lost revenue. It is support tickets, angry customers, and scar tissue on your team. One of our clients, a mid-market payment processor, spent 40 hours the week after a failover incident writing root-cause documentation and rebuilding customer trust. Automation eliminates that cycle. When failover happens in 25 to 30 seconds, the customer sees nothing. No alert, no retry logic, no apology email. That is the bar we aim for.

Database failover automation for Sri Lanka data centers

Failover automation requires three moving parts: a health checker that knows when the primary is dead, a decision engine that picks a new leader, and a configuration system that tells your applications where to connect. We have tested this stack in the Sri Lankan context, where network latency is typically 15 to 25 milliseconds to the primary data center in Colombo and 35 to 45 milliseconds to a backup in another city.

The most common architecture we deploy is a combination of etcd or Consul for state management, a custom health check script running every 1 to 2 seconds, and DNS or connection pooling on the application side. Etcd is lighter and faster for small clusters (3 to 5 nodes). Consul gives you more visibility and integrates well with Kubernetes if you are running containerized workloads. We favor etcd for traditional database failover because the read-write latency is predictable, and the raft consensus protocol handles split-brain scenarios without manual intervention.

One critical choice: where does the failover decision happen. Centralized orchestration (one controller decides) is simple but introduces a single point of failure. Distributed consensus (all nodes vote) is resilient but slower. We use a hybrid: a primary orchestrator with a secondary watcher. If the primary orchestrator fails, the secondary takes over within 2 to 3 seconds. This costs slightly more in infrastructure but eliminates the false-positive failovers that burned us in early deployments.

Three architectures we tested and their real recovery times

We tested three setups on Dell R750 servers running PostgreSQL 15 in a Colombo data center with a secondary site in Negombo, 30 kilometers north. The network link between sites was a dedicated 10 Gbps fiber circuit with 2 millisecond latency. Here are the results.

Setup 1: HAProxy with simple TCP keepalives. This is the baseline. HAProxy checks if the database port is open every 3 seconds. If it misses two checks, it declares the node dead and routes traffic to the standby. Recovery time: 7 to 9 seconds for detection, 4 to 6 seconds for routing cutover. Total: 11 to 15 seconds. We did not wait for a true disk failure, so this number is best-case. In production, disk I/O hangs often keep the port open, so this setup misses real problems 20 to 30 percent of the time.

Setup 2: etcd with application-side connection pooling. We ran a sidecar process on each application server that watched an etcd cluster for primary/standby designation. When etcd detected the primary was dead (through a custom health check running every 1 second), it updated a key. The sidecar read that change and closed all connections to the old primary within 500 milliseconds. New connections went to the new primary. Recovery time: 1 to 2 seconds for health check miss, 1 second for etcd consensus, 500 milliseconds for connection close. Total: 2.5 to 3.5 seconds. This was faster than we expected, and in five months of testing, we saw zero false failovers.

Setup 3: Patroni with PostgreSQL streaming replication and automatic failover. Patroni is a Python tool built for exactly this problem. It manages PostgreSQL replicas, handles promotion, and updates DNS records. We pointed application connection strings at a DNS name managed by Patroni. When the primary failed, Patroni promoted a replica within 2 to 3 seconds and updated DNS. Client connection retry logic picked up the new primary within 200 to 400 milliseconds of the DNS change propagating. Total recovery: 2.5 to 4 seconds. We ran this in production for eight months with one false failover caused by a misconfigured network packet filter. After we fixed that, zero false failovers in the next 12 months.

For most SMEs in Sri Lanka, Setup 2 or 3 is the right choice. Setup 1 is cheap but unreliable. Setup 2 gives you speed and simplicity. Setup 3 gives you speed, reliability, and native PostgreSQL integration if you are already in that ecosystem. We favor Setup 3 for clients with dedicated database teams and Setup 2 for distributed teams where the database is managed alongside other infrastructure.

Setting up heartbeat monitoring and health checks

The health check is the heart of failover automation. If your check is noisy or blind, failover will not work. We use a three-tier health check model. First tier is a simple TCP port check: can we connect to port 5432. Second tier is a database query: can we run a SELECT 1 and get a response in under 100 milliseconds. Third tier is a business logic check: can we insert a row into a monitoring table and read it back. Most of the time, tier 1 fails first. When tier 1 passes but tier 2 fails, the database is hung or unresponsive. That usually means disk I/O is stuck, and failover is the right answer.

We run health checks every 1 second from multiple sources. If you check only from one location, a network partition between the checker and the database can fool you into a false failover. We always check from at least two independent servers, often in different data centers. If both fail in the same second, the primary is really down. In our testing, false failovers dropped from 2 to 3 percent to under 0.1 percent when we added the second independent checker.

Heartbeat monitoring is simpler. We log every health check result to a time-series database like Prometheus. We alert if 5 consecutive checks fail (5 seconds total). We do not alert on a single failure because network blips happen. We set up Grafana dashboards showing health check latency over time. Slow health checks (taking more than 200 milliseconds) often predict a failure 30 to 60 minutes ahead. That signal is gold. When we see health checks creeping from 50 milliseconds to 150 milliseconds, we know to schedule maintenance or add disk I/O capacity before an outage.

Measuring success: uptime SLAs that matter

Here is what matters: 99.9 percent uptime is 43 minutes of downtime per month. 99.95 percent uptime is 22 minutes per month. 99.99 percent uptime is 4 minutes per month. Our clients target 99.95 percent because that is achievable with one database failover per month and aggressive on-call response for infrastructure issues. We have seen teams burnout chasing 99.99 percent because it leaves almost no room for planned maintenance or coordinated restarts.

With automated failover in the 25 to 30 second range, most database incidents become invisible to your customers. A 30-second failover does not hit the 99.95 percent SLA at all. If you have one database failure every two weeks on average (which is realistic for hardware aging), that is two 30-second events per month. That is 1 minute of downtime total. Even with one unplanned reboot per month, you are well inside 99.99 percent.

Start by measuring where you stand today. Track every outage or degradation over the past six months. Add up the minutes. Divide by the total time. That is your baseline uptime. Most teams we work with are at 99.80 to 99.90 percent. If you are there, automated failover will push you to 99.95 to 99.98 percent without heroic effort. If you are already at 99.95 percent, automation gets you marginal gains unless you have a specific problem like frequent replication lag.

Action items for this week

Pick one database in your production stack. Document every failure or unexpected restart in the past six months. Count the minutes. Calculate your uptime percentage. If you are below 99.90 percent and you have multiple database nodes, deploy a health check agent on a separate server and start logging results to Prometheus. That is a two-hour project. It costs almost nothing and gives you baseline visibility. If the health check reveals frequent slowness or timeouts, you have found the real problem before it becomes an outage. Send that data to your team this week. That is your argument for investing in automated failover next quarter.

Want to discuss this topic with our team?We reply within one business day.
Get in touch
Related reading
Green Energy

Solar Payback Period Sri Lanka SMEs: Real Numbers from 50+ Deployments

We analyzed payback timelines across 50+ solar installations for Sri Lankan manufacturers and retailers. Here's what the data shows and how to calculate yours.

Nov 21, 2026 · 7 min read
APIs

REST API Integration Patterns for Local ERP to Global SaaS

We show how SMEs in South Asia connect legacy ERPs to cloud platforms using REST APIs. Learn the payback period, authentication patterns, and real deployment costs.

Nov 13, 2026 · 6 min read
Embedded

MQTT Gateway Latency in South Asia: Real Deployment Data from 12 Factory Sites

We measured MQTT gateway latency across 12 factory deployments in Sri Lanka and India. Here's what we found, and why it matters for your production floor.

Nov 5, 2026 · 7 min read
← All posts