Volume 11 · Chapter 4 — Banking Production Support and Troubleshooting

Database and Data-Tier Troubleshooting

Goutham Mayaluri 8 min read AWSCloudBankingTroubleshootingProduction

4.1 Introduction

The database is usually the hardest part of a system to scale and one of the most common sources of production problems - slow queries, exhausted connections, replication lag, locking, and saturation. Because the data tier is so often the real bottleneck, being able to troubleshoot it is a high-value skill. This chapter covers the common database and data-tier problems in production, their symptoms and causes, and how to diagnose and mitigate them - practical knowledge that comes up constantly in banking support and in interviews.

4.2 Slow Queries

Symptom: database operations are slow, dragging up application latency. Common causes: a missing index forcing a full scan, an inefficient or poorly-written query, a query returning far too much data, or a query made expensive by data growth. Diagnosis: identify the slow queries (slow-query logs, database performance insights) and examine their execution - a query doing a full table scan or handling huge row counts stands out. Response: add the missing index, rewrite the inefficient query, limit the data returned, or introduce caching for frequently-repeated reads. Slow queries are one of the most common data-tier problems and remain the customer’s responsibility even on a managed database, so query and index tuning is a core support skill - a single bad query can saturate the database and slow everything.

flowchart TB
  DB{Data-tier symptom?} -->|Slow ops| SQ[Slow queries:\nmissing index, inefficient query;\nadd index / rewrite / cache]
  DB -->|Connection errors| CE[Connection exhaustion:\nleak or too many; pooling]
  DB -->|Stale reads| RL[Replica lag:\nasync replication; read primary\nwhere freshness needed]
  DB -->|Timeouts/deadlocks| LK[Locking/contention:\nlong txns, hot rows;\nshorten txns, tune isolation]
  DB -->|Maxed out| SAT[Saturation:\noffload reads, scale, fix queries]

4.3 Connection Exhaustion

Symptom: the application can’t get database connections - “too many connections” errors, timeouts acquiring a connection. Common causes: connection leaks (the application not releasing connections back), too many application instances each holding connections (especially as you scale out), or simply exceeding the database’s connection limit. Diagnosis: check the database’s active connection count against its limit and whether it’s climbing (a leak) or just high (too many). Response: use connection pooling so connections are reused rather than each request opening its own; fix leaks by ensuring connections are always released; and for many instances, a connection proxy/pooler in front of the database consolidates connections. Connection exhaustion is a classic scaling pain point because naive scaling of stateless app instances multiplies database connections until the limit is hit.

4.4 Replication Lag and Stale Reads

Symptom: reads return slightly stale data - a value just written isn’t visible on a read. Common cause: asynchronous read replicas lagging behind the primary, so a read routed to a replica sees an older state. This is expected behaviour of async replication, not a bug, but it surprises people. Diagnosis: check replica lag metrics and whether the affected read was served by a replica. Response: route reads that require the latest data to the primary (read-your-writes consistency where needed), and tolerate slight lag on reads that don’t; reduce lag by addressing replica load or replication bottlenecks. The key understanding is that read replicas trade strict freshness for read scaling, so you deliberately choose which reads can use replicas and which must hit the primary - correctness-critical reads (like a balance authorizing a payment) go to the primary.

4.5 Locking, Contention, and Saturation

Symptom: transactions block, time out, or deadlock, or the database is simply saturated. Locking and contention arise when transactions hold locks on the same rows and serialize or deadlock - common causes are long-running transactions holding locks too long, hot rows that many transactions contend for, or an isolation level causing more locking than needed. Diagnosis and response: keep transactions short so locks are released quickly, reduce contention on hot rows, choose an appropriate isolation level, and use the concurrency approach (locking or optimistic) suited to the workload. Saturation - the database maxed on CPU, memory, I/O, or connections - is addressed by offloading reads to replicas and cache, fixing the queries or leaks consuming resources, and scaling the database. Since the data tier is the usual bottleneck, these are among the most impactful mitigations.

4.6 Banking Production Scenario

A bank’s support team troubleshoots data-tier problems methodically. When latency traces point to the database, they check slow-query insights, find a query doing a full scan after a data-model change, and add the missing index - latency recovers. When the app reports connection errors after scaling out, they recognize connection exhaustion from many instances and put a connection pooler in front of the database. When a customer sees a just-made transfer not yet reflected, they identify replica lag and ensure balance-critical reads go to the primary. When transactions time out during a batch, they find a long-running transaction holding locks and shorten it. Because they know the data tier’s common failure modes and their fixes, they resolve these quickly - crucial given the database is the heart of a bank’s system and its most common bottleneck.

4.7 Troubleshooting: Data-Tier Blind Spots

Data-tier problems are missed or mishandled for specific reasons. Application slowness with no obvious cause often is a slow query - trace into the database and check slow-query logs rather than only looking at the app. Connection errors after scaling mean naive scaling multiplied connections - add pooling. Stale-read complaints treated as bugs are usually expected replica lag - route freshness-critical reads to the primary. Transaction timeouts and deadlocks mean locking contention - shorten transactions and reduce hot-row contention. A saturated database treated by only scaling compute misses the real fix - offload reads, fix queries, and cache. The recurring blind spot is not looking at the data tier when it’s actually the bottleneck; since it usually is, the discipline is to trace into the database, examine queries, connections, replication, and locking, and apply the specific fix rather than only tuning the application layer.

Interview Question

The database is the bottleneck in a production incident. How do you troubleshoot it?

Since the database is usually the hardest part to scale and the most common bottleneck, I troubleshoot it by identifying which of the classic data-tier problems is occurring and applying the specific fix. First, slow queries, one of the most common issues: if database operations are slow and dragging up application latency, I identify the slow queries using slow-query logs or performance insights and examine their execution - a query doing a full table scan from a missing index, an inefficient query, or one returning far too much data stands out - and I respond by adding the missing index, rewriting the query, limiting the data returned, or caching frequently-repeated reads; a single bad query can saturate the database and slow everything, and query and index tuning remain my responsibility even on a managed database. Second, connection exhaustion: if the application gets “too many connections” errors or times out acquiring one, the cause is usually a connection leak, too many app instances each holding connections after scaling out, or exceeding the connection limit; I check the active connection count against the limit and whether it’s climbing (a leak) or just high, and respond with connection pooling so connections are reused, fixing leaks so connections are always released, and a connection proxy in front of the database to consolidate connections from many instances - this is a classic scaling pain point. Third, replication lag and stale reads: if a just-written value isn’t visible on a read, it’s usually an async read replica lagging behind the primary, which is expected behaviour, not a bug; I check replica lag metrics and respond by routing reads that need the latest data to the primary while tolerating slight lag elsewhere - a balance authorizing a payment must read the primary. Fourth, locking and contention: if transactions block, time out, or deadlock, it’s usually long-running transactions holding locks, hot rows many transactions contend for, or an over-strict isolation level; I keep transactions short, reduce hot-row contention, and choose the right isolation and concurrency approach. And underlying several of these is saturation - the database maxed on CPU, memory, I/O, or connections - which I address by offloading reads to replicas and cache, fixing the queries or leaks consuming resources, and scaling the database, rather than only scaling application compute. The recurring discipline is to actually trace into the database when it’s the bottleneck - which it usually is - and examine queries, connections, replication, and locking, then apply the targeted fix, because the most common blind spot is tuning the application layer while the real problem is in the data tier. So I diagnose which data-tier failure mode it is - slow queries, connection exhaustion, replica lag, locking, or saturation - and apply its specific remedy, which is how you resolve the database bottleneck that sits at the heart of most serious incidents.

Chapter Revision Notes

  • Slow queries (missing index, inefficient query): identify via slow-query logs; add index, rewrite, limit data, or cache - query tuning is yours even on managed DBs.
  • Connection exhaustion (leaks or too many instances after scaling): use connection pooling and a proxy; fix leaks; a classic scaling pain point.
  • Replication lag/stale reads: expected with async replicas; route freshness-critical reads to the primary, tolerate lag elsewhere.
  • Locking/contention (blocked/deadlocked transactions): shorten transactions, reduce hot-row contention, tune isolation and concurrency approach.
  • Saturation: offload reads to replicas/cache, fix consuming queries/leaks, then scale - not just scaling app compute.