InterviewHubPRO
Section Overview
Q58

Question 58 of 60

Part 5: Real-Time Architecture, Replication & Scale (51 - 60)

97%
Databases & System Design•Part 5: Real-Time Architecture, Replication & Scale (51 - 60)

Connection Starvation & Circuit Breakers:

In Simple Words: If the database slows down, waiting requests hold connection pool slots until the pool starves. A Circuit Breaker detects failures and trips open, failing fast without overwhelming the database.

typescript
// Circuit breaker state check before DB query:
async function executeWithCircuitBreaker(queryFn: () => Promise<any>) {
  if (circuitBreaker.isOpen()) {
    throw new Error('503 Service Unavailable: Database Circuit Breaker Open');
  }
  try {
    return await queryFn();
  } catch (err) {
    circuitBreaker.recordFailure();
    throw err;
  }
}