forgecommandline 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- forgecli/__init__.py +2 -0
- forgecli/ads.py +322 -0
- forgecli/agent.py +1093 -0
- forgecli/art.py +574 -0
- forgecli/attach.py +246 -0
- forgecli/brief.py +215 -0
- forgecli/browsercheck.py +99 -0
- forgecli/checkpoints.py +81 -0
- forgecli/city.py +833 -0
- forgecli/cli.py +1668 -0
- forgecli/config.py +194 -0
- forgecli/courier.py +177 -0
- forgecli/courier_data.py +164 -0
- forgecli/courier_hd.py +431 -0
- forgecli/courier_hd_data.bin +0 -0
- forgecli/courier_hd_data.py +19 -0
- forgecli/ghlogin.py +76 -0
- forgecli/github.py +54 -0
- forgecli/guards.py +403 -0
- forgecli/hooks.py +50 -0
- forgecli/httpapi.py +434 -0
- forgecli/images.py +110 -0
- forgecli/keys.py +152 -0
- forgecli/keyvault.py +320 -0
- forgecli/mcp.py +674 -0
- forgecli/memory.py +42 -0
- forgecli/openapi.py +331 -0
- forgecli/parallel.py +308 -0
- forgecli/prices.py +72 -0
- forgecli/procs.py +144 -0
- forgecli/providers.py +758 -0
- forgecli/quality.py +192 -0
- forgecli/repomap.py +78 -0
- forgecli/roster.py +227 -0
- forgecli/safety.py +93 -0
- forgecli/sandbox.py +83 -0
- forgecli/sessions.py +97 -0
- forgecli/skills.py +446 -0
- forgecli/tools.py +1184 -0
- forgecli/ui.py +860 -0
- forgecli/worktrees.py +79 -0
- forgecommandline-0.8.0.data/data/skills/commit/SKILL.md +14 -0
- forgecommandline-0.8.0.data/data/skills/debug/SKILL.md +17 -0
- forgecommandline-0.8.0.data/data/skills/explain/SKILL.md +14 -0
- forgecommandline-0.8.0.data/data/skills/init/SKILL.md +19 -0
- forgecommandline-0.8.0.data/data/skills/library/LICENSES/agent-skills-MIT.txt +21 -0
- forgecommandline-0.8.0.data/data/skills/library/LICENSES/wondelai-MIT.txt +23 -0
- forgecommandline-0.8.0.data/data/skills/library/README.md +9 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/accessibility-checklist.md +160 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/definition-of-done.md +67 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/observability-checklist.md +92 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/orchestration-patterns.md +370 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/performance-checklist.md +238 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/security-checklist.md +248 -0
- forgecommandline-0.8.0.data/data/skills/library/_references/testing-patterns.md +235 -0
- forgecommandline-0.8.0.data/data/skills/library/api-and-interface-design/SKILL.md +367 -0
- forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/SKILL.md +279 -0
- forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/references/artifact-templates.md +157 -0
- forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/references/methods.md +87 -0
- forgecommandline-0.8.0.data/data/skills/library/awwwards-tier-web-application/SKILL.md +877 -0
- forgecommandline-0.8.0.data/data/skills/library/browser-testing-with-devtools/SKILL.md +317 -0
- forgecommandline-0.8.0.data/data/skills/library/ci-cd-and-automation/SKILL.md +390 -0
- forgecommandline-0.8.0.data/data/skills/library/code-review-and-quality/SKILL.md +398 -0
- forgecommandline-0.8.0.data/data/skills/library/code-simplification/SKILL.md +331 -0
- forgecommandline-0.8.0.data/data/skills/library/constraint-driven-development/SKILL.md +311 -0
- forgecommandline-0.8.0.data/data/skills/library/constraint-driven-development/references/floor-guard.md +182 -0
- forgecommandline-0.8.0.data/data/skills/library/context-engineering/SKILL.md +353 -0
- forgecommandline-0.8.0.data/data/skills/library/debugging-and-error-recovery/SKILL.md +300 -0
- forgecommandline-0.8.0.data/data/skills/library/deprecation-and-migration/SKILL.md +247 -0
- forgecommandline-0.8.0.data/data/skills/library/documentation-and-adrs/SKILL.md +297 -0
- forgecommandline-0.8.0.data/data/skills/library/doubt-driven-development/SKILL.md +243 -0
- forgecommandline-0.8.0.data/data/skills/library/frontend-ui-engineering/SKILL.md +340 -0
- forgecommandline-0.8.0.data/data/skills/library/git-workflow-and-versioning/SKILL.md +355 -0
- forgecommandline-0.8.0.data/data/skills/library/idea-refine/SKILL.md +193 -0
- forgecommandline-0.8.0.data/data/skills/library/idea-refine/examples.md +238 -0
- forgecommandline-0.8.0.data/data/skills/library/idea-refine/frameworks.md +99 -0
- forgecommandline-0.8.0.data/data/skills/library/idea-refine/refinement-criteria.md +113 -0
- forgecommandline-0.8.0.data/data/skills/library/idea-refine/scripts/idea-refine.sh +15 -0
- forgecommandline-0.8.0.data/data/skills/library/improve-code-quality/SKILL.md +275 -0
- forgecommandline-0.8.0.data/data/skills/library/improve-code-quality/references/artifact-templates.md +101 -0
- forgecommandline-0.8.0.data/data/skills/library/incremental-implementation/SKILL.md +249 -0
- forgecommandline-0.8.0.data/data/skills/library/interview-me/SKILL.md +235 -0
- forgecommandline-0.8.0.data/data/skills/library/observability-and-instrumentation/SKILL.md +238 -0
- forgecommandline-0.8.0.data/data/skills/library/performance-optimization/SKILL.md +267 -0
- forgecommandline-0.8.0.data/data/skills/library/performance-optimization/references/optimization-patterns.md +250 -0
- forgecommandline-0.8.0.data/data/skills/library/planning-and-task-breakdown/SKILL.md +257 -0
- forgecommandline-0.8.0.data/data/skills/library/remove-technical-debt/SKILL.md +203 -0
- forgecommandline-0.8.0.data/data/skills/library/remove-technical-debt/references/artifact-templates.md +79 -0
- forgecommandline-0.8.0.data/data/skills/library/security-and-hardening/SKILL.md +216 -0
- forgecommandline-0.8.0.data/data/skills/library/security-and-hardening/references/hardening-patterns.md +324 -0
- forgecommandline-0.8.0.data/data/skills/library/shipping-and-launch/SKILL.md +336 -0
- forgecommandline-0.8.0.data/data/skills/library/source-driven-development/SKILL.md +216 -0
- forgecommandline-0.8.0.data/data/skills/library/spec-driven-development/SKILL.md +259 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/SKILL.md +207 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/building-blocks.md +272 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/common-designs.md +257 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/database-scaling.md +295 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/estimation-numbers.md +250 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/four-step-process.md +286 -0
- forgecommandline-0.8.0.data/data/skills/library/system-design/references/reliability-operations.md +373 -0
- forgecommandline-0.8.0.data/data/skills/library/test-driven-development/SKILL.md +398 -0
- forgecommandline-0.8.0.data/data/skills/library/using-agent-skills/SKILL.md +192 -0
- forgecommandline-0.8.0.data/data/skills/review/SKILL.md +16 -0
- forgecommandline-0.8.0.data/data/skills/run/SKILL.md +17 -0
- forgecommandline-0.8.0.data/data/skills/security-review/SKILL.md +20 -0
- forgecommandline-0.8.0.data/data/skills/simplify/SKILL.md +18 -0
- forgecommandline-0.8.0.data/data/skills/test/SKILL.md +16 -0
- forgecommandline-0.8.0.data/data/skills/web-build/SKILL.md +25 -0
- forgecommandline-0.8.0.dist-info/METADATA +357 -0
- forgecommandline-0.8.0.dist-info/RECORD +113 -0
- forgecommandline-0.8.0.dist-info/WHEEL +5 -0
- forgecommandline-0.8.0.dist-info/entry_points.txt +2 -0
- forgecommandline-0.8.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# The Four-Step System Design Process
|
|
2
|
+
|
|
3
|
+
A structured framework for approaching any system design problem. Each step has a clear purpose, time allocation, and set of deliverables.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Step 1: Understand the Problem & Establish Design Scope (~5-10 min)
|
|
9
|
+
Step 2: Propose High-Level Design & Get Buy-In (~15-20 min)
|
|
10
|
+
Step 3: Design Deep Dive (~15-20 min)
|
|
11
|
+
Step 4: Wrap Up (~5 min)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Total: ~45-60 minutes for a complete design session. Adjust proportionally for shorter or longer sessions.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Step 1: Understand the Problem & Establish Design Scope
|
|
19
|
+
|
|
20
|
+
### Purpose
|
|
21
|
+
|
|
22
|
+
Ensure you and your audience agree on what the system needs to do, how big it needs to be, and what constraints apply. Ambiguity here cascades into wasted effort later.
|
|
23
|
+
|
|
24
|
+
### What to Do
|
|
25
|
+
|
|
26
|
+
**Ask clarifying questions.** Never assume. The difference between a system that serves 1,000 users and one that serves 100 million users is fundamental, not incremental.
|
|
27
|
+
|
|
28
|
+
### Functional Requirements
|
|
29
|
+
|
|
30
|
+
Define what the system does:
|
|
31
|
+
|
|
32
|
+
- What are the core features?
|
|
33
|
+
- Who are the users? (end users, internal services, third-party integrations)
|
|
34
|
+
- What are the key use cases? Walk through the most important user flows.
|
|
35
|
+
- What are the inputs and outputs?
|
|
36
|
+
- Are there any features explicitly out of scope?
|
|
37
|
+
|
|
38
|
+
**Example questions for a URL shortener:**
|
|
39
|
+
- Can users create custom short URLs or only auto-generated ones?
|
|
40
|
+
- Do short URLs expire?
|
|
41
|
+
- Do we need analytics (click count, referrer, geo)?
|
|
42
|
+
- Do we need to support URL deletion or editing?
|
|
43
|
+
|
|
44
|
+
### Non-Functional Requirements
|
|
45
|
+
|
|
46
|
+
Define how the system behaves:
|
|
47
|
+
|
|
48
|
+
| Requirement | Questions to Ask |
|
|
49
|
+
|-------------|-----------------|
|
|
50
|
+
| **Scale** | How many DAU? How many requests per day? Peak vs average? |
|
|
51
|
+
| **Latency** | What is the acceptable response time? P50, P95, P99? |
|
|
52
|
+
| **Availability** | What SLA? 99.9%? 99.99%? |
|
|
53
|
+
| **Consistency** | Strong consistency required or eventual consistency acceptable? |
|
|
54
|
+
| **Durability** | Can we lose data? What is the acceptable RPO? |
|
|
55
|
+
| **Security** | Authentication? Authorization? Encryption at rest/in transit? |
|
|
56
|
+
|
|
57
|
+
### Back-of-the-Envelope Estimates
|
|
58
|
+
|
|
59
|
+
Establish order-of-magnitude numbers:
|
|
60
|
+
|
|
61
|
+
- **QPS:** DAU x actions-per-user / 86,400
|
|
62
|
+
- **Peak QPS:** Average QPS x 2-5 (depends on traffic pattern)
|
|
63
|
+
- **Storage:** Records-per-day x record-size x retention-period
|
|
64
|
+
- **Bandwidth:** QPS x average-response-size
|
|
65
|
+
|
|
66
|
+
### Deliverables from Step 1
|
|
67
|
+
|
|
68
|
+
- Written list of functional requirements (3-5 bullet points)
|
|
69
|
+
- Written list of non-functional requirements (scale, latency, availability)
|
|
70
|
+
- Back-of-the-envelope estimates (QPS, storage, bandwidth)
|
|
71
|
+
- Explicit out-of-scope items
|
|
72
|
+
|
|
73
|
+
### Common Mistakes in Step 1
|
|
74
|
+
|
|
75
|
+
| Mistake | Consequence | Fix |
|
|
76
|
+
|---------|------------|-----|
|
|
77
|
+
| Skipping clarification | Solving the wrong problem | Ask at least 5 clarifying questions |
|
|
78
|
+
| Assuming scale | Over-engineering or under-engineering | Get explicit DAU and QPS numbers |
|
|
79
|
+
| Ignoring non-functional requirements | System works but is too slow/unreliable | Always ask about latency, availability, consistency |
|
|
80
|
+
| Spending too long | Not enough time for design | Timebox to 10 minutes maximum |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Step 2: Propose High-Level Design & Get Buy-In
|
|
85
|
+
|
|
86
|
+
### Purpose
|
|
87
|
+
|
|
88
|
+
Create a blueprint that shows the major components, their responsibilities, and how data flows between them. This is the "skeleton" that Step 3 will flesh out.
|
|
89
|
+
|
|
90
|
+
### What to Do
|
|
91
|
+
|
|
92
|
+
**Draw a diagram.** Include:
|
|
93
|
+
|
|
94
|
+
1. **Clients:** Web, mobile, API consumers
|
|
95
|
+
2. **API Gateway / Load Balancer:** Entry point for requests
|
|
96
|
+
3. **Application Services:** The business logic layer, broken into services if appropriate
|
|
97
|
+
4. **Data Stores:** Databases, caches, blob storage, search indices
|
|
98
|
+
5. **Supporting Infrastructure:** Message queues, CDN, notification services
|
|
99
|
+
6. **Data Flow Arrows:** Show the direction and nature of communication (sync HTTP, async queue, etc.)
|
|
100
|
+
|
|
101
|
+
### API Design
|
|
102
|
+
|
|
103
|
+
Define the key API endpoints:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
POST /api/v1/urls # Create short URL
|
|
107
|
+
GET /api/v1/urls/{id} # Redirect to original URL
|
|
108
|
+
GET /api/v1/urls/{id}/stats # Get analytics
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
For each endpoint, specify:
|
|
112
|
+
- HTTP method and path
|
|
113
|
+
- Request parameters / body
|
|
114
|
+
- Response format
|
|
115
|
+
- Error codes
|
|
116
|
+
|
|
117
|
+
### Data Model
|
|
118
|
+
|
|
119
|
+
Define the core entities and their relationships:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
URL:
|
|
123
|
+
id: bigint (primary key)
|
|
124
|
+
short_code: varchar(7) (unique index)
|
|
125
|
+
original_url: text
|
|
126
|
+
user_id: bigint (foreign key)
|
|
127
|
+
created_at: timestamp
|
|
128
|
+
expires_at: timestamp (nullable)
|
|
129
|
+
click_count: bigint (default 0)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Choose the storage technology:
|
|
133
|
+
- Relational (PostgreSQL, MySQL) for structured data with complex queries
|
|
134
|
+
- Key-value (Redis, DynamoDB) for simple lookups at massive scale
|
|
135
|
+
- Document (MongoDB) for flexible schema
|
|
136
|
+
- Wide-column (Cassandra, HBase) for high write throughput with time-series data
|
|
137
|
+
|
|
138
|
+
### Get Buy-In
|
|
139
|
+
|
|
140
|
+
Before diving deeper:
|
|
141
|
+
- "Does this high-level approach make sense?"
|
|
142
|
+
- "Are there any major concerns with this direction?"
|
|
143
|
+
- "Should we focus the deep dive on [component A] or [component B]?"
|
|
144
|
+
|
|
145
|
+
### Deliverables from Step 2
|
|
146
|
+
|
|
147
|
+
- High-level architecture diagram with labeled components and data flow arrows
|
|
148
|
+
- API contract for the core endpoints
|
|
149
|
+
- Data model for the primary entities
|
|
150
|
+
- Storage technology choice with brief justification
|
|
151
|
+
- Agreement on which components deserve a deep dive
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Step 3: Design Deep Dive
|
|
156
|
+
|
|
157
|
+
### Purpose
|
|
158
|
+
|
|
159
|
+
Take the 2-3 most critical or complex components from the high-level design and design them in detail. This is where you demonstrate depth of knowledge.
|
|
160
|
+
|
|
161
|
+
### Choosing What to Deep Dive
|
|
162
|
+
|
|
163
|
+
Pick components that are:
|
|
164
|
+
- **Hardest to scale:** The database, the real-time messaging layer, the search index
|
|
165
|
+
- **Most critical for correctness:** The payment processor, the consistency model, the rate limiter
|
|
166
|
+
- **Most novel or unique:** Whatever makes this system different from a textbook example
|
|
167
|
+
|
|
168
|
+
### How to Deep Dive
|
|
169
|
+
|
|
170
|
+
For each component:
|
|
171
|
+
|
|
172
|
+
**1. State the specific challenge**
|
|
173
|
+
"The news feed service needs to assemble a personalized feed from thousands of followed accounts within 200ms."
|
|
174
|
+
|
|
175
|
+
**2. Explore design options**
|
|
176
|
+
Present at least two approaches with tradeoffs:
|
|
177
|
+
|
|
178
|
+
| Approach | Pros | Cons |
|
|
179
|
+
|----------|------|------|
|
|
180
|
+
| Fanout-on-write | Fast read, pre-computed | Expensive for celebrity accounts, wastes storage |
|
|
181
|
+
| Fanout-on-read | Cheap writes, fresh data | Slow reads, high read-time computation |
|
|
182
|
+
| Hybrid | Balanced for most cases | More complex, two code paths |
|
|
183
|
+
|
|
184
|
+
**3. Choose and justify**
|
|
185
|
+
"We choose the hybrid approach because 99% of accounts have < 10K followers (fanout-on-write is cheap), and the 1% celebrity accounts use fanout-on-read to avoid write amplification."
|
|
186
|
+
|
|
187
|
+
**4. Detail the implementation**
|
|
188
|
+
- Data structures and algorithms
|
|
189
|
+
- Database schema additions
|
|
190
|
+
- Caching strategy
|
|
191
|
+
- Error handling and edge cases
|
|
192
|
+
|
|
193
|
+
### Deep Dive Examples
|
|
194
|
+
|
|
195
|
+
**URL shortener -- ID generation deep dive:**
|
|
196
|
+
- Option A: Auto-increment ID + base62 encoding (simple, sequential, single-point bottleneck)
|
|
197
|
+
- Option B: Pre-generated ID ranges per server (distributed, no coordination, slight complexity)
|
|
198
|
+
- Option C: Hash of original URL (deterministic, possible collisions, needs collision handling)
|
|
199
|
+
- Choice: Option B for scalability with Option C as a fallback for deduplication
|
|
200
|
+
|
|
201
|
+
**Chat system -- message delivery deep dive:**
|
|
202
|
+
- WebSocket connection management at scale
|
|
203
|
+
- Message ordering guarantees (per-conversation monotonic IDs)
|
|
204
|
+
- Offline message storage and delivery on reconnect
|
|
205
|
+
- Read receipts and presence (heartbeat-based, eventual consistency acceptable)
|
|
206
|
+
|
|
207
|
+
### Deliverables from Step 3
|
|
208
|
+
|
|
209
|
+
- Detailed design of 2-3 critical components
|
|
210
|
+
- Tradeoff analysis for each design decision
|
|
211
|
+
- Data structures, schemas, or algorithms where relevant
|
|
212
|
+
- Edge case handling
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Step 4: Wrap Up
|
|
217
|
+
|
|
218
|
+
### Purpose
|
|
219
|
+
|
|
220
|
+
Summarize the design, acknowledge its limitations, and suggest future improvements. This demonstrates maturity and self-awareness.
|
|
221
|
+
|
|
222
|
+
### What to Cover
|
|
223
|
+
|
|
224
|
+
**1. Summary of the design**
|
|
225
|
+
One-paragraph overview of how the system works end-to-end.
|
|
226
|
+
|
|
227
|
+
**2. Tradeoffs acknowledged**
|
|
228
|
+
- "We chose eventual consistency for the news feed, which means a post may take 1-2 seconds to appear in all followers' feeds."
|
|
229
|
+
- "Sharding by user_id means cross-user queries (e.g., trending topics) require scatter-gather."
|
|
230
|
+
|
|
231
|
+
**3. Bottlenecks identified**
|
|
232
|
+
- "The database write path will be the first bottleneck at 50K QPS."
|
|
233
|
+
- "Hot users with millions of followers will stress the fanout service."
|
|
234
|
+
|
|
235
|
+
**4. Future improvements**
|
|
236
|
+
- "Add a CDN for frequently accessed short URLs."
|
|
237
|
+
- "Implement rate limiting per API key to prevent abuse."
|
|
238
|
+
- "Add a circuit breaker for downstream service calls."
|
|
239
|
+
|
|
240
|
+
**5. Error handling and edge cases**
|
|
241
|
+
- What happens when the database is down?
|
|
242
|
+
- What happens when the cache is full?
|
|
243
|
+
- How do we handle duplicate requests?
|
|
244
|
+
- How do we handle schema migrations?
|
|
245
|
+
|
|
246
|
+
### Deliverables from Step 4
|
|
247
|
+
|
|
248
|
+
- One-paragraph design summary
|
|
249
|
+
- List of acknowledged tradeoffs
|
|
250
|
+
- Identified bottlenecks and scaling triggers
|
|
251
|
+
- Suggested future improvements
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Tips for Each Step
|
|
256
|
+
|
|
257
|
+
### General Tips
|
|
258
|
+
|
|
259
|
+
- **Think out loud.** The process is as important as the result.
|
|
260
|
+
- **Use numbers.** "A lot of traffic" is vague; "50K QPS" is actionable.
|
|
261
|
+
- **Draw diagrams.** Visual communication is clearer than verbal descriptions.
|
|
262
|
+
- **Name your tradeoffs.** Every decision has a cost; acknowledging it shows depth.
|
|
263
|
+
|
|
264
|
+
### Step 1 Tips
|
|
265
|
+
|
|
266
|
+
- Ask open-ended questions first, then narrow down
|
|
267
|
+
- Write down assumptions explicitly -- don't keep them in your head
|
|
268
|
+
- If given incomplete information, state your assumption and move on
|
|
269
|
+
|
|
270
|
+
### Step 2 Tips
|
|
271
|
+
|
|
272
|
+
- Start with the simplest design that could work, then add complexity
|
|
273
|
+
- Label every arrow in the diagram (HTTP, gRPC, async message, etc.)
|
|
274
|
+
- Don't design microservices for a system that could be a monolith
|
|
275
|
+
|
|
276
|
+
### Step 3 Tips
|
|
277
|
+
|
|
278
|
+
- Go deep on 2-3 things rather than shallow on everything
|
|
279
|
+
- Compare at least two approaches before choosing
|
|
280
|
+
- Address failure modes: what happens when this component goes down?
|
|
281
|
+
|
|
282
|
+
### Step 4 Tips
|
|
283
|
+
|
|
284
|
+
- Be honest about what you didn't cover
|
|
285
|
+
- Propose monitoring and alerting for the bottlenecks you identified
|
|
286
|
+
- Mention operational concerns: deployment, data migration, feature flags
|
forgecommandline-0.8.0.data/data/skills/library/system-design/references/reliability-operations.md
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# Reliability and Operations
|
|
2
|
+
|
|
3
|
+
A system is only as good as its ability to stay up, recover from failures, and be observed. This reference covers the operational practices that turn a design diagram into a production system.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
1. [Health Checks](#health-checks)
|
|
8
|
+
2. [Monitoring and Alerting](#monitoring-and-alerting)
|
|
9
|
+
3. [Logging](#logging)
|
|
10
|
+
4. [Deployment Strategies](#deployment-strategies)
|
|
11
|
+
5. [Disaster Recovery](#disaster-recovery)
|
|
12
|
+
6. [Data Center Redundancy](#data-center-redundancy)
|
|
13
|
+
7. [Autoscaling](#autoscaling)
|
|
14
|
+
8. [Operational Readiness Checklist](#operational-readiness-checklist)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Health Checks
|
|
19
|
+
|
|
20
|
+
### Liveness vs Readiness
|
|
21
|
+
|
|
22
|
+
Two fundamentally different questions:
|
|
23
|
+
|
|
24
|
+
| Check | Question | What Happens on Failure |
|
|
25
|
+
|-------|----------|------------------------|
|
|
26
|
+
| **Liveness** | Is the process alive and not deadlocked? | Restart the process |
|
|
27
|
+
| **Readiness** | Can this instance serve traffic right now? | Remove from load balancer (but don't restart) |
|
|
28
|
+
|
|
29
|
+
### Implementation
|
|
30
|
+
|
|
31
|
+
**Liveness probe (`/healthz` or `/livez`):**
|
|
32
|
+
```
|
|
33
|
+
Returns 200 if:
|
|
34
|
+
- Process is running
|
|
35
|
+
- Main thread is responsive
|
|
36
|
+
- No deadlock detected
|
|
37
|
+
|
|
38
|
+
Returns 503 if:
|
|
39
|
+
- Event loop is blocked
|
|
40
|
+
- Process is in an unrecoverable state
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Readiness probe (`/readyz` or `/ready`):**
|
|
44
|
+
```
|
|
45
|
+
Returns 200 if:
|
|
46
|
+
- Database connection is active
|
|
47
|
+
- Cache connection is active
|
|
48
|
+
- Required downstream services are reachable
|
|
49
|
+
- Startup initialization is complete
|
|
50
|
+
|
|
51
|
+
Returns 503 if:
|
|
52
|
+
- Any critical dependency is unreachable
|
|
53
|
+
- Still warming up (loading cache, running migrations)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Best Practices
|
|
57
|
+
|
|
58
|
+
- Liveness checks should be simple and fast (< 100ms) -- don't check external dependencies
|
|
59
|
+
- Readiness checks should verify all critical dependencies
|
|
60
|
+
- Set appropriate thresholds: don't restart on a single failure (3 consecutive failures is typical)
|
|
61
|
+
- Include version and build info in health check response for debugging
|
|
62
|
+
- Separate health check endpoints for different concerns (database, cache, queue)
|
|
63
|
+
|
|
64
|
+
### Kubernetes Configuration
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
livenessProbe:
|
|
68
|
+
httpGet:
|
|
69
|
+
path: /healthz
|
|
70
|
+
port: 8080
|
|
71
|
+
initialDelaySeconds: 15
|
|
72
|
+
periodSeconds: 10
|
|
73
|
+
failureThreshold: 3
|
|
74
|
+
|
|
75
|
+
readinessProbe:
|
|
76
|
+
httpGet:
|
|
77
|
+
path: /readyz
|
|
78
|
+
port: 8080
|
|
79
|
+
initialDelaySeconds: 5
|
|
80
|
+
periodSeconds: 5
|
|
81
|
+
failureThreshold: 2
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Monitoring and Alerting
|
|
87
|
+
|
|
88
|
+
### The Three Pillars of Observability
|
|
89
|
+
|
|
90
|
+
| Pillar | What It Captures | Tools | Use Case |
|
|
91
|
+
|--------|-----------------|-------|----------|
|
|
92
|
+
| **Metrics** | Numeric measurements over time | Prometheus, Datadog, CloudWatch | Dashboards, alerting, trend analysis |
|
|
93
|
+
| **Logs** | Discrete events with context | ELK (Elasticsearch, Logstash, Kibana), CloudWatch Logs, Splunk | Debugging, audit trails, error investigation |
|
|
94
|
+
| **Traces** | Request journey across services | Jaeger, Zipkin, AWS X-Ray, Datadog APM | Latency analysis, dependency mapping, bottleneck identification |
|
|
95
|
+
|
|
96
|
+
### Key Metrics to Track
|
|
97
|
+
|
|
98
|
+
#### The Four Golden Signals (Google SRE)
|
|
99
|
+
|
|
100
|
+
| Signal | What It Measures | Example Metric |
|
|
101
|
+
|--------|-----------------|----------------|
|
|
102
|
+
| **Latency** | Time to serve a request | P50, P95, P99 response time |
|
|
103
|
+
| **Traffic** | Demand on the system | Requests per second (QPS) |
|
|
104
|
+
| **Errors** | Rate of failed requests | 5xx error rate, timeout rate |
|
|
105
|
+
| **Saturation** | How full the system is | CPU utilization, memory usage, queue depth |
|
|
106
|
+
|
|
107
|
+
#### The RED Method (for request-driven services)
|
|
108
|
+
|
|
109
|
+
- **Rate:** Requests per second
|
|
110
|
+
- **Errors:** Errors per second
|
|
111
|
+
- **Duration:** Distribution of request latency
|
|
112
|
+
|
|
113
|
+
#### The USE Method (for resources)
|
|
114
|
+
|
|
115
|
+
- **Utilization:** Percentage of resource in use (CPU at 80%)
|
|
116
|
+
- **Saturation:** Work queued because resource is busy (run queue length)
|
|
117
|
+
- **Errors:** Error events on the resource (disk I/O errors)
|
|
118
|
+
|
|
119
|
+
### Alerting Best Practices
|
|
120
|
+
|
|
121
|
+
| Practice | Why | Example |
|
|
122
|
+
|----------|-----|---------|
|
|
123
|
+
| **Alert on symptoms, not causes** | Users care about latency, not CPU | Alert on "P99 latency > 500ms" not "CPU > 80%" |
|
|
124
|
+
| **Severity levels** | Not everything is a page | Critical (page on-call), Warning (ticket), Info (log) |
|
|
125
|
+
| **Include runbook link** | Responder needs context | Alert message includes link to troubleshooting steps |
|
|
126
|
+
| **Avoid alert fatigue** | Too many alerts = ignored alerts | Review and prune alerts quarterly; every alert must be actionable |
|
|
127
|
+
| **Set appropriate thresholds** | Too sensitive = noise; too lenient = missed issues | Use percentile-based thresholds (P99 > X) rather than averages |
|
|
128
|
+
|
|
129
|
+
### Dashboard Design
|
|
130
|
+
|
|
131
|
+
Every service should have a standard dashboard with:
|
|
132
|
+
|
|
133
|
+
1. **Request rate** (QPS) -- is traffic normal?
|
|
134
|
+
2. **Error rate** (4xx, 5xx) -- are requests failing?
|
|
135
|
+
3. **Latency** (P50, P95, P99) -- are requests slow?
|
|
136
|
+
4. **Saturation** (CPU, memory, disk, connections) -- are resources exhausted?
|
|
137
|
+
5. **Dependencies** (downstream error rate, latency) -- are dependencies healthy?
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Logging
|
|
142
|
+
|
|
143
|
+
### Log Levels
|
|
144
|
+
|
|
145
|
+
| Level | When to Use | Example |
|
|
146
|
+
|-------|------------|---------|
|
|
147
|
+
| **ERROR** | Something failed and needs attention | Database connection lost, payment processing failed |
|
|
148
|
+
| **WARN** | Something unexpected but handled | Retry succeeded, deprecated API called |
|
|
149
|
+
| **INFO** | Normal operational events | Request processed, user logged in, deployment started |
|
|
150
|
+
| **DEBUG** | Detailed diagnostic information | SQL queries, request/response bodies, cache hits/misses |
|
|
151
|
+
|
|
152
|
+
### Structured Logging
|
|
153
|
+
|
|
154
|
+
Always use structured (JSON) logging, not plain text:
|
|
155
|
+
|
|
156
|
+
**Bad:**
|
|
157
|
+
```
|
|
158
|
+
2024-01-15 10:23:45 ERROR Failed to process order 12345 for user 678
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Good:**
|
|
162
|
+
```json
|
|
163
|
+
{
|
|
164
|
+
"timestamp": "2024-01-15T10:23:45Z",
|
|
165
|
+
"level": "ERROR",
|
|
166
|
+
"message": "Failed to process order",
|
|
167
|
+
"order_id": "12345",
|
|
168
|
+
"user_id": "678",
|
|
169
|
+
"error": "payment_declined",
|
|
170
|
+
"trace_id": "abc-123-def",
|
|
171
|
+
"service": "order-service",
|
|
172
|
+
"duration_ms": 2340
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Best Practices
|
|
177
|
+
|
|
178
|
+
- Include a correlation/trace ID in every log entry (links logs across services)
|
|
179
|
+
- Never log sensitive data (passwords, tokens, full credit card numbers, PII)
|
|
180
|
+
- Log at request boundaries (request received, response sent, downstream calls)
|
|
181
|
+
- Set appropriate retention (7 days for DEBUG, 30 days for INFO, 90+ days for ERROR)
|
|
182
|
+
- Use log aggregation (ELK, CloudWatch, Splunk) -- never rely on SSH-ing into servers
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Deployment Strategies
|
|
187
|
+
|
|
188
|
+
### Rolling Deployment
|
|
189
|
+
|
|
190
|
+
**How it works:** Replace instances one at a time. At any point, some instances run the old version and some run the new version.
|
|
191
|
+
|
|
192
|
+
| Pros | Cons |
|
|
193
|
+
|------|------|
|
|
194
|
+
| Zero downtime | Two versions running simultaneously (must be backward-compatible) |
|
|
195
|
+
| Simple to implement | Slow rollout for large fleets |
|
|
196
|
+
| Easy rollback (stop rolling, roll backward) | Mixed-version issues during deployment |
|
|
197
|
+
|
|
198
|
+
**Best for:** Stateless services, backward-compatible changes.
|
|
199
|
+
|
|
200
|
+
### Blue-Green Deployment
|
|
201
|
+
|
|
202
|
+
**How it works:** Run two identical environments (blue and green). Deploy new version to green. Switch traffic from blue to green. Keep blue as instant rollback.
|
|
203
|
+
|
|
204
|
+
| Pros | Cons |
|
|
205
|
+
|------|------|
|
|
206
|
+
| Instant rollback (switch back to blue) | Double the infrastructure cost |
|
|
207
|
+
| No mixed versions | Database schema changes are tricky (both versions need to work) |
|
|
208
|
+
| Full testing of green before switch | Requires sophisticated load balancer or DNS switching |
|
|
209
|
+
|
|
210
|
+
**Best for:** Critical services where instant rollback is essential.
|
|
211
|
+
|
|
212
|
+
### Canary Deployment
|
|
213
|
+
|
|
214
|
+
**How it works:** Route a small percentage of traffic (1-5%) to the new version. Compare metrics (latency, error rate) between old and new. Gradually increase traffic if metrics are healthy.
|
|
215
|
+
|
|
216
|
+
| Pros | Cons |
|
|
217
|
+
|------|------|
|
|
218
|
+
| Low risk (small blast radius) | More complex infrastructure |
|
|
219
|
+
| Real production testing | Requires good monitoring to detect issues |
|
|
220
|
+
| Data-driven promotion decisions | Two versions running simultaneously |
|
|
221
|
+
|
|
222
|
+
**Canary progression:**
|
|
223
|
+
1. Deploy to 1-2% of traffic
|
|
224
|
+
2. Wait 10-30 minutes, compare metrics
|
|
225
|
+
3. If healthy: increase to 10%, wait, compare
|
|
226
|
+
4. If healthy: increase to 50%, wait, compare
|
|
227
|
+
5. If healthy: promote to 100%
|
|
228
|
+
6. At any step: if metrics degrade, rollback to 0%
|
|
229
|
+
|
|
230
|
+
**Best for:** Large-scale services where you want data-driven confidence.
|
|
231
|
+
|
|
232
|
+
### Feature Flags
|
|
233
|
+
|
|
234
|
+
**How it works:** Deploy code with features behind flags. Enable features independently of deployment.
|
|
235
|
+
|
|
236
|
+
| Pros | Cons |
|
|
237
|
+
|------|------|
|
|
238
|
+
| Decouple deployment from release | Flag management complexity |
|
|
239
|
+
| Per-user or per-segment rollout | Dead flags accumulate (tech debt) |
|
|
240
|
+
| Instant disable without deployment | Testing combinatorial complexity |
|
|
241
|
+
|
|
242
|
+
**Best combined with:** Canary deployment. Deploy the code, then canary the feature flag.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Disaster Recovery
|
|
247
|
+
|
|
248
|
+
### RPO and RTO
|
|
249
|
+
|
|
250
|
+
Two metrics define your disaster recovery requirements:
|
|
251
|
+
|
|
252
|
+
| Metric | Question | Example |
|
|
253
|
+
|--------|----------|---------|
|
|
254
|
+
| **RPO (Recovery Point Objective)** | How much data can you afford to lose? | RPO = 1 hour means you need at least hourly backups |
|
|
255
|
+
| **RTO (Recovery Time Objective)** | How long can you be down? | RTO = 15 minutes means automated failover is required |
|
|
256
|
+
|
|
257
|
+
### Disaster Recovery Strategies
|
|
258
|
+
|
|
259
|
+
| Strategy | RPO | RTO | Cost | How It Works |
|
|
260
|
+
|----------|-----|-----|------|-------------|
|
|
261
|
+
| **Backup and restore** | Hours | Hours | Low | Periodic backups to S3; restore on failure |
|
|
262
|
+
| **Pilot light** | Minutes | Minutes-hours | Medium | Minimal replica running; scale up on failure |
|
|
263
|
+
| **Warm standby** | Seconds-minutes | Minutes | High | Scaled-down replica always running; scale up on failure |
|
|
264
|
+
| **Multi-site active-active** | Near-zero | Near-zero | Very high | Full copy in each region; both serve traffic |
|
|
265
|
+
|
|
266
|
+
### Backup Best Practices
|
|
267
|
+
|
|
268
|
+
- **3-2-1 rule:** 3 copies, 2 different media types, 1 offsite
|
|
269
|
+
- **Test restores regularly** -- an untested backup is not a backup
|
|
270
|
+
- **Automate backup verification** -- checksum validation, test restore to staging
|
|
271
|
+
- **Encrypt backups** -- at rest and in transit
|
|
272
|
+
- **Define retention** -- daily for 7 days, weekly for 4 weeks, monthly for 12 months
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Data Center Redundancy
|
|
277
|
+
|
|
278
|
+
### Active-Passive
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
Primary DC: Serves all traffic
|
|
282
|
+
Secondary DC: Hot standby, receives replicated data
|
|
283
|
+
Failover: DNS or load balancer switches to secondary
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
| Pros | Cons |
|
|
287
|
+
|------|------|
|
|
288
|
+
| Simpler (one write path) | Wasted capacity in passive DC |
|
|
289
|
+
| No conflict resolution needed | Failover takes time (DNS TTL, warmup) |
|
|
290
|
+
| Clear data authority | Secondary may have replication lag |
|
|
291
|
+
|
|
292
|
+
### Active-Active
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
DC-A: Serves region A traffic, replicates to DC-B
|
|
296
|
+
DC-B: Serves region B traffic, replicates to DC-A
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
| Pros | Cons |
|
|
300
|
+
|------|------|
|
|
301
|
+
| Full utilization of both DCs | Write conflicts between DCs |
|
|
302
|
+
| Lower latency (users hit nearest DC) | Complex data synchronization |
|
|
303
|
+
| No failover needed (traffic redirects) | Must handle split-brain scenarios |
|
|
304
|
+
|
|
305
|
+
### Key Challenges
|
|
306
|
+
|
|
307
|
+
| Challenge | Solution |
|
|
308
|
+
|-----------|---------|
|
|
309
|
+
| **Data synchronization** | Async replication with conflict resolution (LWW, CRDTs) |
|
|
310
|
+
| **Session management** | Centralized session store (Redis) or stateless sessions (JWT) |
|
|
311
|
+
| **Cache consistency** | Accept eventual consistency or use distributed cache |
|
|
312
|
+
| **Traffic routing** | GeoDNS routes users to nearest DC; health-check-based failover |
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Autoscaling
|
|
317
|
+
|
|
318
|
+
### What to Scale On
|
|
319
|
+
|
|
320
|
+
| Metric | When to Use | Example |
|
|
321
|
+
|--------|------------|---------|
|
|
322
|
+
| **CPU utilization** | Compute-bound workloads | Scale up when CPU > 70% for 5 minutes |
|
|
323
|
+
| **Memory utilization** | Memory-bound workloads | Scale up when memory > 80% |
|
|
324
|
+
| **Request rate** | Traffic-driven scaling | Scale up when QPS > 1000 per instance |
|
|
325
|
+
| **Queue depth** | Worker-based processing | Scale up when queue > 10,000 messages |
|
|
326
|
+
| **Custom metrics** | Business-specific | Scale up when active WebSocket connections > 5,000 per instance |
|
|
327
|
+
|
|
328
|
+
### Scaling Configuration
|
|
329
|
+
|
|
330
|
+
| Parameter | Recommendation | Why |
|
|
331
|
+
|-----------|---------------|-----|
|
|
332
|
+
| **Min instances** | At least 2 (for redundancy) | Survives single instance failure |
|
|
333
|
+
| **Max instances** | Set a cap (cost protection) | Prevents runaway scaling from bugs or attacks |
|
|
334
|
+
| **Scale-up threshold** | 70% utilization | Leave headroom for traffic spikes during scale-up |
|
|
335
|
+
| **Scale-down threshold** | 30% utilization | Avoid flapping (scaling up and down repeatedly) |
|
|
336
|
+
| **Cooldown period** | 5-10 minutes | Prevents rapid oscillation |
|
|
337
|
+
|
|
338
|
+
### Scaling Strategies
|
|
339
|
+
|
|
340
|
+
| Strategy | How It Works | Best For |
|
|
341
|
+
|----------|-------------|----------|
|
|
342
|
+
| **Reactive** | Scale based on current metrics | Unpredictable traffic |
|
|
343
|
+
| **Scheduled** | Pre-scale for known patterns | Predictable peaks (morning rush, end-of-day batch) |
|
|
344
|
+
| **Predictive** | ML-based prediction of future load | Gradual ramps with some predictability |
|
|
345
|
+
|
|
346
|
+
### Common Autoscaling Mistakes
|
|
347
|
+
|
|
348
|
+
| Mistake | Consequence | Fix |
|
|
349
|
+
|---------|------------|-----|
|
|
350
|
+
| No max limit | Runaway costs or resource exhaustion | Always set max instances |
|
|
351
|
+
| Scaling on average, not percentile | Miss tail latency issues | Scale on P95/P99 latency or queue depth |
|
|
352
|
+
| Too aggressive cooldown | Flapping (scale up, scale down, repeat) | Set cooldown to 5-10 minutes |
|
|
353
|
+
| Scaling only the web tier | Database becomes bottleneck | Scale all tiers (web, cache, database connections) |
|
|
354
|
+
| No load testing | Unknown scaling behavior | Load test to find breaking points before production |
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## Operational Readiness Checklist
|
|
359
|
+
|
|
360
|
+
Before going to production, verify:
|
|
361
|
+
|
|
362
|
+
| Category | Check |
|
|
363
|
+
|----------|-------|
|
|
364
|
+
| **Health** | Liveness and readiness probes configured |
|
|
365
|
+
| **Monitoring** | Dashboard with four golden signals |
|
|
366
|
+
| **Alerting** | Critical alerts with runbooks |
|
|
367
|
+
| **Logging** | Structured logs with trace IDs |
|
|
368
|
+
| **Deployment** | Rollback plan tested |
|
|
369
|
+
| **Scaling** | Autoscaling configured with min/max |
|
|
370
|
+
| **Backup** | Backup schedule defined, restore tested |
|
|
371
|
+
| **DR** | RPO/RTO defined, failover tested |
|
|
372
|
+
| **Security** | Secrets in vault, TLS everywhere, access controlled |
|
|
373
|
+
| **Documentation** | Architecture diagram, runbooks, on-call rotation |
|