What Would Uzair Do? · Issue #02

What to Do When Business Growth Outpaces Existing Software

The architectural decisions that enable early product velocity can become liabilities when customer volume and concurrent transactions surge. When database timeouts, double-bookings, and webhook retry storms threaten reliability during critical commercial periods, here is how a systems architect triages the bottleneck without derailing the roadmap with a risky, multi-year full rebuild.

1. The Direct Answer

When customer growth overwhelms your software, avoid the trap of a premature full rewrite. A complete ground-up rebuild during rapid business expansion introduces substantial commercial risk: it ties up core engineering capacity for multiple quarters, delays urgent feature delivery to paying customers, and frequently introduces subtle edge-case defects that the existing production system solved long ago.

Instead, apply targeted architectural decoupling at the point of highest contention. Software systems rarely fail everywhere simultaneously; they fail at specific, identifiable bottlenecks:

  • Database Record Locking (Row Contention): When multiple customers or background jobs attempt to update the exact same account balance, inventory slot, or booking record at the identical millisecond, the database forces transactions to wait in line, causing query pools to exhaust.
  • Synchronous Dependency Chains: When a user initiates a transaction (e.g. checkout), and the application forces them to wait while it sequentially communicates with payment processors, email services, and analytics webhooks before confirming success.
  • Cache Thundering Herds: When a high-traffic product page or dashboard cache expires during a traffic spike, causing hundreds of concurrent requests to hammer the underlying database simultaneously for the exact same data.

2. What I Investigate First

When brought into a scaling business experiencing performance degradation or intermittent outages, I run a systematic pre-mortem triage:

  1. Transaction Isolation & Lock Telemetry: Where are queries waiting for table or row-level locks? Are heavy analytical reporting queries running on the primary write database rather than dedicated read replicas?
  2. Asynchronous Task Decoupling: Which third-party dependencies (such as payment gateways, notification APIs, or ERP syncs) are executed synchronously inside the user's request-response cycle rather than being offloaded to background queues?
  3. Idempotency & Retry Resilience: When a payment gateway or partner webhook experiences a network timeout, does the system safely deduplicate retries, or does it risk duplicate order placement and double-charges?
The Scalability Rule

A system scales not by making individual operations run infinitely fast, but by preventing independent operations from waiting on shared locks.

3. Practical Architectural Solutions

Pattern A: Atomic Event Queuing (The Outbox Pattern)

In early application code, an endpoint often writes an order, sends confirmation emails, updates inventory, and notifies carriers all within one synchronous HTTP request. If any external service delays for three seconds, the user's browser hangs and database connections remain tied up.

The Fix: Implement atomic event queuing (the Transactional Outbox pattern) paired with background workers (such as AWS SQS or Celery/RabbitMQ). The web request simply writes the order and records a lightweight message in an outbox table within a single atomic database transaction, returning a response in milliseconds. Dedicated background workers then process notifications, third-party syncs, and webhooks asynchronously with exponential backoff and dead-letter queues.

Pattern B: Distributed Mutex Locks (Concurrency Protection)

When multiple concurrent users attempt to claim the last inventory unit, confirm the same appointment slot, or debit an account simultaneously, basic database read-then-write checks allow race condition collisions.

The Fix: Deploy a distributed lock pattern using an in-memory datastore (such as Redis with atomic token leases). Before an allocation begins, the system acquires a temporary exclusive lock. If a duplicate concurrent request arrives, it can be queued or returned with an informative status message. Because a lease can expire while a worker is paused, enforce fencing at the protected resource and database-level invariants for critical writes, as discussed in the experience section below.

Pattern C: Hierarchical Caching & Dedicated Read Replicas

Allowing thousands of concurrent read queries to hit your primary database during marketing campaigns or peak trading hours will starve critical write transactions of CPU and I/O capacity.

The Fix: Direct all read-only dashboard lookups, catalog searches, and public listings to read replicas. Introduce an in-memory caching tier in front of hot queries, applying automated background cache refreshing before keys expire to prevent thundering-herd spikes during traffic bursts.

4. An Illustrative Concurrency Scenario

The following scenario illustrates a common architectural pattern in transaction processing:

The Operational Friction: An affiliate and transaction platform experiences bursts of thousands of partner webhook events per minute during seasonal sales. The primary monolithic database slows down under lock contention, leading to HTTP timeouts. Merchant partners automatically retry failed requests, doubling the traffic load and creating race-condition discrepancies in user account balances.

The Architectural Solution: The engineering team separates high-speed webhook ingestion from financial accounting:

  • An edge ingestion barrier validates partner cryptographic signatures and enforces strict idempotency keys in Redis before placing events into an asynchronous processing queue.
  • Accounting transactions are executed by background workers enforcing an immutable double-entry ledger with row-level locks strictly scoped to individual accounts.

The Business Outcome: Webhook ingestion safely absorbs sudden traffic spikes without database lock starvation, and the design aims to reduce balance discrepancies, subject to reconciliation and failure testing.

5. What to Measure to Confirm System Health

  • P99 Latency under Load: Monitor response times for the slowest 1% of users during peak traffic. If P99 latency rises steeply while average latency stays flat, database query queuing is occurring.
  • Database Lock Wait Time: Track active sessions waiting on database lock events in telemetry dashboards.
  • Dead-Letter Queue Volume: Ensure failed background jobs are routed to dead-letter queues for systematic investigation and replaying rather than failing silently.

For organizations reviewing scaling trade-offs or untangling legacy systems, explore our SaaS Architecture Advisory or our Production Architecture Pre-Mortem for fixed-scope architectural evaluations.

Experience from a multi-partner rewards platform

When evolving high-traffic rewards and commerce backends away from tightly coupled monoliths, partner ingestion events and consumer-facing financial balances must enforce very different consistency boundaries. Defining explicit domain ownership prevents distributed deployment complexity from slowing feature teams down.

A Redis lease can expire while its holder is paused. Use a unique ownership token and atomic compare-and-delete on release; where stale writers matter, enforce monotonically increasing fencing tokens at the protected resource. A database uniqueness constraint, transaction, and idempotency key remain necessary for financial correctness. A lease alone does not guarantee it.

Are Scaling Outages Threatening Your Growth?

Before you lose customer trust or commit to an unmanageable full rebuild, let's identify the exact architectural bottleneck. Tell me what is failing under load, and I will outline a targeted decoupling plan.

Discuss an Architecture Problem