import sys
import json
from typing import List, Dict
class ChecklistGenerator:
def __init__(self):
# The Knowledge Base of Failure Modes
self.question_bank = {
# --- Architecture Specific ---
"microservices": [
"Service Discovery: If the service registry (e.g., Consul, Eureka) fails, can services communicate via fallback or cache?",
"Cascading Failure: Are Circuit Breakers (e.g., Hystrix, Resilience4j) implemented to prevent a single slow service from taking down the whole mesh?",
"Data Consistency: How does the system handle the 'Eventual Consistency' window if a downstream database is temporarily unavailable?"
],
"monolith": [
"Resource Exhaustion: If one module leaks memory, does it starve the entire application? Have you considered resource isolation (e.g., separate worker pools)?",
"Deployment Impact: Can you perform blue/green or canary deployments, or does every deploy require full downtime?",
"Single Point of Failure: Is this running on a single node? If so, is the checklist actually 'Design for Recovery' rather than 'Design for Failure'?"
],
"serverless": [
"Cold Starts: How does the system behave if a sudden spike triggers 1000 cold starts simultaneously?",
"Vendor Throttling: Do you have fallback logic for AWS/GCP API rate limits (e.g., DynamoDB throughput exceeded)?",
"State Management: Are you relying on local disk or in-memory state that won't persist across function invocations?"
],
# --- Dependency Specific ---
"database_sql": [
"Connection Pooling: Is the connection pool limit set high enough for traffic, but low enough not to crash the DB?",
"Migration Lock: What happens if a schema migration locks the database during peak hours?",
"Primary Failure: Is automatic failover to a read-replica configured, and are you ready for eventual consistency during the switchover?"
],
"third_party_api": [
"SLA Mismatch: Is your timeout shorter than the third party's p99 latency?",
"Non-Critical Dependency: If this API goes down, does your core user flow degrade gracefully or crash completely?",
"Authentication Rot: What happens if the API key rotates or expires unexpectedly?"
],
"message_queue": [
"Consumer Lag: If the consumer falls behind by 1 hour, is the data still relevant?",
"Poison Pill: How do you handle a message that crashes the consumer infinitely? Is there a Dead Letter Queue (DLQ)?",
"Backpressure: Does the producer throttle when the queue depth exceeds a threshold?"
],
# --- Historical Outage Specific ---
"incident_db_connection_exhaustion": [
"Have you implemented a 'Kill Switch' to shed non-critical load when DB connections run dry?",
"Are you monitoring 'Active Threads' vs 'Idle Threads' specifically, or just total connections?"
],
"incident_latency_spike": [
"Have you implemented distinct timeouts for 'Connection' vs 'Read' operations?",
"Is there an automated rollback mechanism if latency exceeds p99.9?"
],
"incident_data_corruption": [
"How recent is your last 'Logical' backup (SQL dump), not just a binary storage snapshot?",
"Do you have a way to selectively replay transaction logs to fix data without full downtime?"
]
}
def collect_inputs(self) -> Dict:
print("--- Architecture & Context Setup ---")
# 1. Architecture
print("\nSelect your Architecture Pattern:")
print("1. Microservices")
print("2. Monolith")
print("3. Serverless")
arch_choice = input("Enter number (1-3): ")
arch_map = {"1": "microservices", "2": "monolith", "3": "serverless"}
architecture = arch_map.get(arch_choice, "microservices")
# 2. Dependencies
print("\nSelect dependencies in use (comma separated):")
print("1. SQL Database")
print("2. External Third-Party API")
print("3. Message Queue (Kafka/RabbitMQ)")
deps_input = input("Enter numbers (e.g., 1,2): ")
deps_list = []
dep_map = {"1": "database_sql", "2": "third_party_api", "3": "message_queue"}
for char in deps_input.split(','):
key = char.strip()
if key in dep_map:
deps_list.append(dep_map[key])
# 3. Historical Outages
print("\nHave you suffered any of these specific outages recently? (comma separated):")
print("1. Database Connection Exhaustion")
print("2. Sudden Latency Spike")
print("3. Data Corruption/Loss")
print("(Leave blank if none)")
hist_input = input("Enter numbers: ")
hist_list = []
hist_map = {"1": "incident_db_connection_exhaustion", "2": "incident_latency_spike", "3": "incident_data_corruption"}
for char in hist_input.split(','):
key = char.strip()
if key in hist_map:
hist_list.append(hist_map[key])
return {
"architecture": architecture,
"dependencies": deps_list,
"history": hist_list
}
def generate_checklist(self, config: Dict) -> List[str]:
checklist = []
# Core Architecture Questions
if config['architecture'] in self.question_bank:
checklist.extend(self.question_bank[config['architecture']])
# Dependency Questions
for dep in config['dependencies']:
if dep in self.question_bank:
checklist.extend(self.question_bank[dep])
# Historical Outage Questions (The "Never Again" section)
for hist in config['history']:
if hist in self.question_bank:
checklist.extend(self.question_bank[hist])
return checklist
def run(self):
config = self.collect_inputs()
checklist = self.generate_checklist(config)
print("\n\n" + "="*50)
print(f" DESIGN FOR FAILURE CHECKLIST ({config['architecture'].upper()})")
print("="*50)
category_map = {
"microservices": "ARCHITECTURE", "monolith": "ARCHITECTURE", "serverless": "ARCHITECTURE",
"database_sql": "DEPENDENCY :: DATABASE", "third_party_api": "DEPENDENCY :: EXTERNAL", "message_queue": "DEPENDENCY :: MESSAGING",
"incident_db_connection_exhaustion": "LESSONS LEARNED", "incident_latency_spike": "LESSONS LEARNED", "incident_data_corruption": "LESSONS LEARNED"
}
# Simple logic to group questions by category for cleaner output
# (In a real app, we would store the category explicitly with the question)
print(f"\n[ ] System Architecture ({config['architecture']})")
print("-" * 40)
for q in self.question_bank.get(config['architecture'], []):
print(f"[ ] {q}")
for dep in config['dependencies']:
dep_name = dep.replace("_", " ").upper()
print(f"\n[ ] Dependency Check: {dep_name}")
print("-" * 40)
for q in self.question_bank.get(dep, []):
print(f"[ ] {q}")
if config['history']:
print(f"\n[!] Historical Outage Checks")
print("-" * 40)
for hist in config['history']:
for q in self.question_bank.get(hist, []):
print(f"[ ] {q}")
print("\n" + "="*50)
print(" END OF CHECKLIST ")
print("="*50)
if __name__ == "__main__":
gen = ChecklistGenerator()
gen.run()