Skip to content

Latest commit

 

History

History
373 lines (268 loc) · 27.7 KB

File metadata and controls

373 lines (268 loc) · 27.7 KB

DevOps Best Practices & Architecture Patterns (100 Questions)

Welcome to the DevOps Best Practices & Architecture Patterns master collection containing 100 comprehensive interview questions and detailed answers covering 12-Factor App methodology, Cloud-Native architecture principles, Disaster Recovery (RTO/RPO), Immutable Infrastructure, Chaos Engineering, SRE Error Budget Governance, and High Availability design patterns.


🟢 Part 1: 12-Factor App & Cloud-Native Foundations (Questions 1–40)

1. Explain the 12-Factor App methodology and how each factor maps to modern Kubernetes architectures.

Answer:

  1. Codebase: One Git repo per microservice; deployed to dev, staging, prod via GitOps.
  2. Dependencies: Explicitly declared and isolated (e.g., go.mod, package.json, locked in container image).
  3. Config: Injected strictly via environment variables (Kubernetes ConfigMaps and Secrets), never hardcoded in images.
  4. Backing Services: Attached resources accessed over network URLs (DATABASE_URL=postgres://...).
  5. Build, Release, Run: Strictly separate build (CI image packaging) and run (CD staging/deploy) stages.
  6. Processes: Execute as stateless, share-nothing processes; state persisted in backing databases/caches.
  7. Port Binding: Self-contained services exporting HTTP/gRPC listeners bound to internal ports (:8080).
  8. Concurrency: Scale horizontally via process replication (Kubernetes Pod replicas via HPA).
  9. Disposability: Maximize robustness with fast startup ($< 2$s) and handling SIGTERM for graceful connection draining.
  10. Dev/Prod Parity: Keep development, staging, and production environments as identical as possible.
  11. Logs: Treat logs as event streams emitted directly to stdout/stderr for log forwarders.
  12. Admin Processes: Run one-off admin tasks (database migrations) as isolated ephemeral Kubernetes Job resources.

2. What is Immutable Infrastructure and what are its operational benefits?

Answer: An operational pattern where servers and containers are never patched or modified in-place. Updates require building a new image/container from scratch, testing it, deploying it, and terminating old instances.

  • Benefits: Eliminates configuration drift, provides deterministic rollbacks, and simplifies disaster recovery.

3. Compare RTO vs RPO in Disaster Recovery with concrete scenarios.

Answer:

  • RTO (Recovery Time Objective): Maximum allowable duration of system downtime after a disaster before service is restored (measures downtime duration).
  • RPO (Recovery Point Objective): Maximum allowable data loss measured backward in time from disaster (measures data loss).
  • Scenario: If backups run at midnight and a disaster strikes at 2:00 AM, RPO is 2 hours of data. If systems take 30 minutes to restore, RTO is 30 minutes.

4. Compare the four primary Cloud Disaster Recovery Strategies.

Answer:

[ Lowest Cost / Highest RTO & RPO ]                                [ Highest Cost / Near-Zero RTO & RPO ]
1. Backup & Restore   ➔   2. Pilot Light   ➔   3. Warm Standby   ➔   4. Multi-Site Active-Active
  1. Backup & Restore: Data backed up to S3/Glacier; compute provisioned from scratch during disaster (RTO: Hours–Days, RPO: Hours).
  2. Pilot Light: Core data replicated continuously; minimal core infrastructure running (RTO: 10s of minutes).
  3. Warm Standby: Scaled-down version of full environment always running; scaled up on failover (RTO: Minutes).
  4. Multi-Site Active-Active: Full production traffic processed across multiple regions simultaneously (RTO: Zero, RPO: Near-zero).

5. What is the Bulkhead Pattern in distributed systems?

Answer: Isolates critical system resources (thread pools, memory, CPU, database connection pools) into distinct compartments for each downstream dependency so that failure of one dependency cannot exhaust all resources and crash the entire application.

6. What is Circuit Breaking and what are its three states?

Answer: A pattern that prevents an application from repeatedly executing an operation that is failing:

  • Closed: Normal operation; requests pass through.
  • Open: Threshold of failures breached; all incoming requests fail fast immediately without calling the failing downstream service.
  • Half-Open: Periodically allows a small trial percentage of requests through to test if the downstream service has recovered.

7. What is Exponential Backoff with Jitter?

Answer: A retry algorithm where wait intervals double with each attempt ($2^n$) combined with randomized variance (jitter) to desynchronize retry storms across clients, solving the Thundering Herd problem.

8. What is the Expand and Contract (Parallel Run) pattern for Zero-Downtime Database Migrations?

Answer:

  1. Expand: Add new columns/tables in a backward-compatible manner (nullable or with default values).
  2. Write Dual: Deploy application version writing to both old and new columns, reading from old.
  3. Backfill: Execute asynchronous background job migrating historical records.
  4. Read New: Deploy application version reading exclusively from the new column.
  5. Contract: Remove old legacy columns in a subsequent release after confirming stability.

9. What is Chaos Engineering and how do you conduct a GameDay?

Answer: Proactively injecting controlled failures (killing pods, adding network latency, severing database links) into production/staging environments to discover hidden systemic vulnerabilities.

  • GameDay: A scheduled cross-functional exercise where teams simulate severe real-world failure scenarios to validate alerting, runbooks, and automatic failover mechanisms.

10. What is SRE Toil and how do you eliminate it?

Answer: Manual, repetitive, automatable operational work devoid of enduring engineering value. Eliminated by enforcing the Google SRE 50% Rule: cap toil at $&lt; 50%$ of an SRE's time, dedicating the remaining time to software engineering projects that permanently automate operational tasks.

11. What is an SLO Error Budget Policy?

Answer: A formal business contract defining agreed-upon operational restrictions: when an error budget reaches 0%, feature deployments are frozen, and 100% of engineering bandwidth shifts to reliability engineering and bug fixing.

12. What is FinOps Unit Cost Economics?

Answer: Measuring cloud spend relative to direct business metrics (e.g., Cost per Active User, Cost per Transaction Processed), identifying whether cloud bill increases are driven by healthy business growth or architectural inefficiencies.

13. What is Pod Anti-Affinity in Kubernetes?

Answer: Scheduling rules instructing Kubernetes to spread replicas of the same application across different physical worker nodes and different cloud Availability Zones to guarantee high availability.

14. What is Rate Limiting vs Load Shedding?

Answer:

  • Rate Limiting: Restricts individual client traffic based on API tokens/IPs (e.g., max 100 req/min per user).
  • Load Shedding: When a server approaches 100% CPU/memory saturation, it intentionally drops low-priority background requests to ensure critical checkout payments succeed with low latency.

15. What is a Blameless Post-Mortem Culture?

Answer: Treating human errors as symptoms of deeper systemic, process, and tooling vulnerabilities rather than individual negligence, focusing on actionable engineering safeguards to prevent recurrence.

16. What is Trunk-Based Development?

Answer: A source control branching model where all developers merge small, frequent commits directly into a single shared branch (main) multiple times a day, avoiding long-lived feature branches and merge conflicts.

17. What is Shift-Left Testing and Security?

Answer: Integrating automated unit tests, SAST, SCA, and compliance checks into the earliest stages of the development cycle to catch defects when they are cheapest to resolve.

18. What is Dark Launching vs Canary Deployments?

Answer:

  • Canary: Exposes a new version to a small percentage of real end users who interact with the new UI/API.
  • Dark Launching: Deploys backend code to production, processing real data in the background or mirroring live traffic without exposing any visible user interface changes.

19. What is Idempotency in DevOps Automation?

Answer: An operation is idempotent if executing it once or multiple times produces the exact same end state without unintended side effects (e.g., terraform apply or ansible-playbook).

20. What is High Availability (HA) and "The Nines"?

Answer:

  • 99.9% (Three Nines): Max 43.8 min downtime/month.
  • 99.99% (Four Nines): Max 4.38 min downtime/month.
  • 99.999% (Five Nines): Max 26.3 sec downtime/month.

21. What is the Strangler Fig Pattern for Legacy Migration?

Answer: Incrementally replacing specific pieces of a monolithic system with modern microservices behind an API Gateway until the legacy monolith is completely deprecated and removed.

22. What is the Sidecar Pattern vs Ambassador Pattern vs Adapter Pattern?

Answer:

  • Sidecar: Extends or enhances the main container without modifying it (e.g., log shipper, metrics exporter).
  • Ambassador: Proxies network communication from the main container to external services (e.g., database proxy, circuit breaker).
  • Adapter: Standardizes and normalizes output from heterogeneous legacy applications (e.g., converting legacy custom logs to standardized Prometheus metrics).

23. What is Graceful Degradation in Microservices?

Answer: Designing systems to remain operational with reduced functionality when non-essential downstream services fail (e.g., showing static top-seller items if the recommendation engine crashes).

24. What is Database Connection Pooling and why is it needed?

Answer: Maintaining a persistent pool of established connections to the database (via PgBouncer / RDS Proxy) to multiplex thousands of client requests over a stable backend connection pool, preventing connection exhaustion.

25. What is the Saga Pattern for Distributed Transactions?

Answer: Managing distributed transactions across microservices via a sequence of local transactions, executing compensating transactions (reversals) if a step fails.

26. What is the Transactional Outbox Pattern?

Answer: Saving events to an "Outbox" database table within the same ACID transaction as business data, and using a separate change-data-capture (Debezium) process to publish events to Kafka.

27. What is CQRS (Command Query Responsibility Segregation)?

Answer: Separating read and write operations into distinct data models and databases optimized specifically for high-throughput writes (Commands) or fast reads (Queries).

28. What is Event Sourcing?

Answer: An architectural pattern where state changes are stored as an append-only sequence of immutable events rather than overwriting current state values in place.

29. What is Write-Ahead Logging (WAL)?

Answer: Recording changes to append-only disk storage before applying them to memory, guaranteeing durability during crashes.

30. What is Distributed Consensus (Raft / Paxos)?

Answer: Algorithms that enable distributed clusters (etcd, Consul, CockroachDB) to agree on state across independent nodes despite network partitions.

31. What is Split-Brain in High Availability Systems?

Answer: A state where network partitions isolate cluster nodes into two groups that both elect leaders, corrupting data. Prevented by requiring an odd number of nodes (3, 5, 7) and strict majority quorum ($\lfloor N/2 \rfloor + 1$).

32. What is the CAP Theorem?

Answer: In a distributed data store with a Network Partition (P), you must choose between Consistency (C - all nodes see the same data) or Availability (A - every request receives a non-error response).

33. What is the PACELC Theorem?

Answer: An extension of CAP: If there is a Partition, choose Availability or Consistency; Else (normal state), choose Latency or Consistency.

34. What is Head-of-Line (HoL) Blocking?

Answer: A performance bottleneck where a single dropped packet in a FIFO queue stalls all subsequent packets (resolved by HTTP/3 QUIC over UDP).

35. What is Zero Trust Microsegmentation?

Answer: Enforcing default-deny network policies and mTLS authentication between every individual microservice inside the cluster.

36. What is Conway’s Law?

Answer: Organizations design systems that mirror their own communication structures.

37. What is Continuous Profiling?

Answer: Low-overhead, continuous collection of CPU, memory, and thread contention call stacks directly from production workloads using kernel eBPF probes.

38. What is High Cardinality in Metrics?

Answer: A metric with a large number of unique label key-value pairs (user_id, email), which exhausts time-series database memory.

39. What is Automated Canary Analysis (ACA)?

Answer: Evaluating real-time statistical telemetry metrics (error rate, p99 latency) comparing canary pods against baseline pods during a deployment to trigger autonomous rollbacks.

40. What is an Enterprise SRE Maturity Model?

Answer:

  1. Reactive monitoring and manual ticketing.
  2. Proactive APM, distributed tracing, and Golden Signals.
  3. SLOs, Error Budget burn-rate alerting, and Chaos GameDays.
  4. Autonomous self-healing systems and continuous resilience verification.

🟡 Part 2: Advanced Reliability, Scaling & Governance (Questions 41–100)

41. What is the Thundering Herd Problem in Caching?

Answer: When a high-traffic cache key expires, thousands of simultaneous incoming requests miss the cache and hit the backend database concurrently, crashing the database. Resolved using Cache Mutex Locking (Singleflight) or Probabilistic Early Expiration (XFetch).

42. What is Cache Penetration vs Cache Breakdown vs Cache Avalanche?

Answer:

  • Cache Penetration: Queries for non-existent keys bypass cache and hit database directly (fixed via Bloom Filters).
  • Cache Breakdown: A single hot key expires, triggering concurrent DB queries (fixed via mutex locking).
  • Cache Avalanche: Many cached keys expire simultaneously, overwhelming the database (fixed by adding randomized TTL jitter).

43. What is a Bloom Filter?

Answer: A space-efficient probabilistic data structure that tests whether an element is definitely not in a set or may be in a set, preventing unnecessary database lookups.

44. What is Read-Through vs Write-Through vs Write-Back Caching?

Answer:

  • Read-Through: Application queries cache; cache fetches from DB on miss.
  • Write-Through: Data written to cache and database synchronously.
  • Write-Back (Write-Behind): Data written to cache immediately; written to database asynchronously in batches.

45. What is Database Connection Pool Sizing Formula (HikariCP)?

Answer: $\text{Pool Size} = (\text{Core Count} \times 2) + \text{Effective Spindle Count}$. Oversized connection pools cause CPU context switching overhead and memory exhaustion.

46. What is Database Read-Write Splitting?

Answer: Routing write transactions (INSERT, UPDATE) to primary master database and read queries (SELECT) to asynchronous read replicas.

47. What is Database Sharding and Shard Key Selection?

Answer: Horizontally partitioning database rows across independent physical database instances based on a consistent hash of the shard key (e.g., hash(user_id) % num_shards).

48. What is Consistent Hashing?

Answer: A hashing technique where nodes and keys are mapped to a virtual ring. Adding or removing a server node only requires remapping $\frac{K}{N}$ keys, minimizing cache disruption.

49. What is Two-Phase Commit (2PC)?

Answer: Distributed consensus protocol across databases: Phase 1 (Prepare / Vote) $\rightarrow$ Phase 2 (Commit). Highly blocking; vulnerable to coordinator node crashes.

50. What is Vector Clock in Distributed Data Stores?

Answer: An algorithm for generating logical timestamps across distributed nodes to determine partial ordering of events and detect causal write conflicts.

51. What is Gossip Protocol in Distributed Systems?

Answer: A peer-to-peer decentralized communication protocol where nodes periodically exchange state information with random peers to spread cluster membership and health data (used in Cassandra and Consul).

52. What is Paxos vs Raft Consensus?

Answer:

  • Paxos: Mathematically elegant, but notoriously complex to understand and implement correctly.
  • Raft: Decomposed consensus algorithm (Leader Election, Log Replication, Safety) designed specifically for understandability and production implementation (powers etcd and Consul).

53. What is Lease-Based Lock in Distributed Systems?

Answer: A lock granted to a client for a finite time duration (TTL). If the client crashes, the lease expires automatically, preventing deadlocks.

54. What is Fencing Token in Distributed Locking?

Answer: A monotonically increasing number issued by a lock service (etcd). Storage systems reject write requests from clients holding older fencing tokens, preventing delayed clients from overwriting newer writes.

55. What is Distributed Rate Limiting using Redis Token Bucket?

Answer: Executing atomic Lua scripts inside Redis to decrement token counts per user/IP over sliding time windows across distributed API gateways.

56. What is Asynchronous Event-Driven Architecture (EDA)?

Answer: Decoupling microservices using event streams (Kafka) and message queues (RabbitMQ), enabling non-blocking communication, horizontal scalability, and burst absorption.

57. What is Backpressure in Streaming Architectures?

Answer: A flow-control mechanism where a downstream consumer informs an upstream producer to slow down message generation when buffers approach saturation.

58. What is Idempotent Consumer Pattern?

Answer: Ensuring duplicate event deliveries (due to at-least-once messaging) do not produce duplicate side effects by recording processed message_id hashes in a deduplication database table.

59. What is Dead Letter Queue (DLQ) Reprocessing Automation?

Answer: Routing poisoned or unprocessable messages to a DLQ, alerting on-call engineers, and providing automated CLI tooling to replay redrive payloads once bugs are patched.

60. What is Compaction in Apache Kafka?

Answer: Retaining only the most recent record value for each primary message key in a topic partition, functioning as a distributed key-value changelog.

61. What is Zero-Downtime Blue-Green Deployment Strategy?

Answer: Running two identical production stacks (Blue = Active, Green = New). Switching 100% traffic instantly at the load balancer upon validating Green health checks.

62. What is Canary Deployment with Automated Metric Analysis?

Answer: Incrementally shifting traffic (2% $\rightarrow$ 10% $\rightarrow$ 50% $\rightarrow$ 100%) while evaluating real-time Prometheus error rate and latency queries to trigger automated rollbacks on degradation.

63. What is Dark Launching vs Feature Flagging?

Answer: Dark launching tests backend capacity with live shadow traffic; Feature flagging dynamically exposes or hides UI capabilities to segmented user cohorts.

64. What is Automated Rollback in GitOps (ArgoCD)?

Answer: Reverting the Git commit in the configuration repository to trigger automated cluster state reconciliation back to the previous stable release.

65. What is Ephemeral Preview Environment Lifecycle?

Answer: Automatically spinning up a complete isolated microservice environment on Kubernetes for every Pull Request and destroying it upon merge to optimize test fidelity.

66. What is Shift-Left Security in CI/CD Pipelines?

Answer: Enforcing secret scanning, SAST, SCA dependency scanning, container image scanning, and IaC linting on every commit before code is merged.

67. What is Software Supply Chain Security (SLSA Level 3)?

Answer: Hermetic build environments, automated CycloneDX SBOM generation, non-falsifiable in-toto provenance, and Cosign cryptographic signing.

68. What is Keyless Image Signing with Sigstore?

Answer: Signing container images using short-lived OIDC tokens from GitHub Actions, generating temporary X.509 certs from Fulcio, and recording signatures in Rekor transparency logs.

69. What is Zero Trust Microsegmentation in Kubernetes?

Answer: Default-deny NetworkPolicies and mutual TLS (mTLS) encryption between every pod, eliminating implicit network trust inside the VPC.

70. What is HashiCorp Vault Dynamic Secrets Management?

Answer: Generating ephemeral database credentials on-demand with short TTLs that are automatically dropped upon lease expiration.

71. What is Policy as Code (Kyverno vs OPA Gatekeeper)?

Answer: Defining, validating, and mutating Kubernetes resources and verifying image signatures using declarative policy code before objects are persisted to etcd.

72. What is Falco eBPF Runtime Security?

Answer: Intercepting Linux kernel system calls in real time to detect unauthorized container activities (spawning shells, modifying /etc/shadow).

73. What is CIS Benchmark Hardening?

Answer: Industry-standard security baseline configuration checks for Linux OS, Docker, and Kubernetes clusters.

74. What is Least Privilege RBAC Governance?

Answer: Granting users, service accounts, and workloads only the minimum necessary permissions required to perform their functions.

75. What is Just-In-Time (JIT) Elevated Access?

Answer: Granting temporary, time-bounded (e.g., 2-hour) elevated production permissions that automatically expire upon task completion.

76. What is SRE Error Budget Exhaustion Policy?

Answer: Freezing non-critical feature releases and redirecting 100% of engineering capacity to reliability, testing, and technical debt reduction when the error budget reaches 0%.

77. What is Multi-Window Multi-Burn-Rate Alerting?

Answer: Calculating the consumption speed of an error budget across multiple time windows (1h and 6h) to page engineers only when significant budget burn occurs.

78. What is SRE Toil Reduction Framework?

Answer: Identifying, categorizing, and tracking operational toil hours, permanently eliminating repetitive manual work via software automation.

79. What is Blameless Post-Mortem 5 Whys Root Cause Analysis?

Answer: Asking "Why?" five consecutive times to drill past surface human mistakes to the fundamental systemic, architectural, and procedural flaws.

80. What is On-Call Escalation Matrix and Rotation?

Answer: Tiered paging schedules (Primary $\rightarrow$ Secondary $\rightarrow$ Engineering Manager) with automated escalation timeouts to ensure 24/7 incident response.

81. What is FinOps Inform, Optimize, Operate Lifecycle?

Answer: Continuous framework providing visibility into cloud spend (Inform), identifying right-sizing and discount opportunities (Optimize), and establishing automated governance (Operate).

82. What is Cloud Unit Cost Metric Formulation?

Answer: Calculating cloud spend relative to direct business KPIs ($\frac{\text{Monthly Cloud Cost}}{\text{Monthly Active Transactions}}$) to measure true infrastructure efficiency.

83. What is Kubernetes Workload Right-Sizing?

Answer: Tuning container CPU and memory resource requests/limits based on historical Prometheus utilization metrics to eliminate cloud compute waste.

84. What is Spot Instance Consolidation in Karpenter?

Answer: Dynamically provisioning and bin-packing diverse Spot instance fleets on Kubernetes, consolidating empty and underutilized nodes automatically.

85. What is Infracost Shift-Left Cost Estimation?

Answer: Posting automated cloud cost delta comments on GitHub PRs to inform engineers of financial impacts before merging infrastructure code.

86. What is AWS Multi-Account Organization Architecture?

Answer: Isolating workloads into dedicated accounts (Log Archive, Security, Shared Services, Dev, Prod) governed by Service Control Policies (SCPs).

87. What is Multi-Region Active-Active Architecture with Aurora Global DB?

Answer: Deploying active compute in multiple cloud regions routing traffic to local clusters with storage-level replication and write-forwarding.

88. What is Disaster Recovery Automated Failover with Route 53?

Answer: DNS health checks monitoring regional /healthz endpoints and triggering automated DNS record failover during regional outages.

89. What is Pilot Light vs Warm Standby DR Strategy?

Answer:

  • Pilot Light: Critical data replicated continuously; core infrastructure scaled down to minimum footprint until disaster.
  • Warm Standby: Scaled-down version of full environment always running; scaled up instantly upon failover.

90. What is AWS Direct Connect vs Site-to-Site VPN Failover?

Answer: Primary dedicated physical fiber connection paired with an automated IPsec VPN backup link orchestrated via dynamic BGP routing.

91. What is AWS Transit Gateway Hub-and-Spoke Networking?

Answer: Centralized virtual router connecting hundreds of VPCs and on-premises data centers with transitive routing and centralized inspection.

92. What is AWS PrivateLink (Interface VPC Endpoints)?

Answer: Private network interfaces connecting VPC subnets to cloud services over AWS internal backbones without public internet routing.

93. What is OpenTelemetry Collector Multi-Pipeline Architecture?

Answer: Configuring independent ingestion, processing (batching, tail sampling, PII redaction), and export pipelines for metrics, logs, and traces.

94. What is Distributed Tracing Span Context Propagation?

Answer: Propagating traceparent and tracestate W3C headers across HTTP and gRPC network boundaries.

95. What is Grafana Tempo Object-Storage Tracing Architecture?

Answer: Storing raw trace spans compressed directly in cloud object storage (S3/GCS) without requiring Elasticsearch.

96. What is Grafana Loki Label Indexing Architecture?

Answer: Indexing only stream metadata labels while storing raw compressed log text in object storage, reducing logging infrastructure costs by 80%.

97. What is eBPF Continuous Profiling with Pyroscope?

Answer: Sampling CPU instruction pointers at fixed frequencies across all processes via Linux kernel eBPF probes, visualizing code bottlenecks in Flame Graphs.

98. What is Prometheus TSDB Chunk Compaction and WAL Checkpointing?

Answer: Appending samples to an in-memory WAL before flushing to 2-hour TSDB blocks, compacted periodically into long-term immutable storage blocks.

99. What is Synthetic Probing vs Real User Monitoring (RUM)?

Answer: Automated headless bots testing user workflows from global edge locations paired with client-side JavaScript telemetry capturing real user latencies.

100. What is Enterprise DevOps Operational Excellence Framework?

Answer:

  1. Automation: 100% Infrastructure as Code and GitOps delivery.
  2. Observability: Golden Signals, distributed tracing, and SLO burn-rate alerting.
  3. Resilience: Chaos Engineering GameDays and automated multi-region DR failover.
  4. Security: Shift-Left DevSecOps, SLSA Level 3 supply chain, and Zero Trust microsegmentation.
  5. FinOps: Unit cost economics and automated Spot instance consolidation.