Network Architecture and Communication Patterns Questions
Design and analysis of network architectures and service communication patterns for reliable, performant, and secure distributed systems. Topics include network topology and capacity planning, load balancing strategies, content delivery networks, caching and edge delivery, application programming interface gateway design, service to service communication patterns including synchronous and asynchronous messaging, message queues, publish subscribe, request routing, retries and backoff, timeouts, idempotency, circuit breakers, bulkheads, and service mesh considerations. Also covers latency optimization, failure modes and resilience, observability and monitoring, network security principles such as encryption and segmentation, and how architectural choices affect scalability and operational complexity.
Sample Answer
Sample Answer
Sample Answer
Sample Answer
import time
import threading
from collections import deque
from enum import Enum
class State(Enum):
CLOSED = 1
OPEN = 2
HALF_OPEN = 3
class CircuitBreaker:
def __init__(self, failure_threshold, request_volume_threshold, reset_timeout_seconds, window_seconds=60):
# thresholds: failure_threshold is percent (0-100)
self.failure_threshold = float(failure_threshold)
self.request_volume_threshold = int(request_volume_threshold)
self.reset_timeout = float(reset_timeout_seconds)
self.window_seconds = float(window_seconds)
self.lock = threading.Lock()
self.state = State.CLOSED
self.window = deque() # entries: (timestamp, success_bool)
self.opened_at = None
self.half_open_trial_in_progress = False
def _prune(self, now):
while self.window and now - self.window[0][0] > self.window_seconds:
self.window.popleft()
def _failure_rate(self, now):
self._prune(now)
total = len(self.window)
if total == 0:
return 0.0, 0
failures = sum(1 for _, success in self.window if not success)
return (failures / total) * 100.0, total
def call(self, func, *args, **kwargs):
now = time.time()
with self.lock:
if self.state == State.OPEN:
if now - (self.opened_at or 0) >= self.reset_timeout:
self.state = State.HALF_OPEN
self.half_open_trial_in_progress = False
else:
raise RuntimeError("Circuit is OPEN")
if self.state == State.HALF_OPEN:
if self.half_open_trial_in_progress:
raise RuntimeError("Circuit is HALF-OPEN and trial in progress")
self.half_open_trial_in_progress = True
# perform call outside lock to avoid blocking
try:
result = func(*args, **kwargs)
success = True
except Exception:
result = None
success = False
with self.lock:
now = time.time()
self.window.append((now, success))
if self.state == State.HALF_OPEN:
self.half_open_trial_in_progress = False
if success:
self.state = State.CLOSED
self.window.clear()
else:
self.state = State.OPEN
self.opened_at = now
elif self.state == State.CLOSED:
rate, total = self._failure_rate(now)
if total >= self.request_volume_threshold and rate >= self.failure_threshold:
self.state = State.OPEN
self.opened_at = now
if not success:
# re-raise to caller for visibility
raise RuntimeError("Wrapped call failed")
return resultSample Answer
Unlock Full Question Bank
Get access to hundreds of Network Architecture and Communication Patterns interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.