-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem-design-tutorial.html
More file actions
531 lines (452 loc) · 19.7 KB
/
Copy pathsystem-design-tutorial.html
File metadata and controls
531 lines (452 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>System Design Architecture Masterclass 🔥</title>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet">
<!-- Highlight.js for Code Formatting -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>
:root {
--bg-color: #0b1120; /* Very deep slate/blue for a cyber tech feel */
--surface-color: #151e32;
--primary-color: #f43f5e; /* Rose / Pinkish Red */
--primary-glow: rgba(244, 63, 94, 0.4);
--text-main: #f8fafc;
--text-muted: #94a3b8;
--border-color: rgba(255, 255, 255, 0.08);
--card-border: rgba(255, 255, 255, 0.1);
--accent-color: #fca5a5;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
font-family: 'Plus Jakarta Sans', sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
line-height: 1.6;
background-image:
radial-gradient(at 0% 0%, rgba(244, 63, 94, 0.15) 0px, transparent 50%),
radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.1) 0px, transparent 50%);
background-attachment: fixed;
min-height: 100vh;
}
.layout {
display: flex;
gap: 2.5rem;
max-width: 1400px;
margin: 0 auto;
padding: 3rem 2rem;
align-items: flex-start;
}
.sidebar {
width: 280px;
flex-shrink: 0;
position: sticky;
top: 3rem;
max-height: calc(100vh - 6rem);
overflow-y: auto;
background: rgba(21, 30, 50, 0.8);
border: 1px solid var(--card-border);
border-radius: 16px;
padding: 1.5rem;
box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.5);
backdrop-filter: blur(12px);
}
.sidebar h3 {
margin-top: 0;
margin-bottom: 1rem;
font-size: 1.1rem;
text-transform: uppercase;
letter-spacing: 1.5px;
color: var(--primary-color);
border-bottom: 1px solid var(--card-border);
padding-bottom: 1rem;
}
.sidebar ul {
list-style: none;
}
.sidebar li {
margin-bottom: 0.3rem;
}
.nav-section {
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-muted);
margin: 1.5rem 0 0.5rem 0;
padding-left: 0.5rem;
font-weight: 700;
}
.sidebar a {
text-decoration: none;
color: var(--text-muted);
display: block;
padding: 0.5rem 1rem;
border-radius: 8px;
transition: all 0.3s ease;
font-size: 0.95rem;
font-weight: 500;
}
.sidebar a:hover {
background: rgba(244, 63, 94, 0.15);
color: var(--primary-color);
transform: translateX(5px);
}
.main-content {
flex: 1;
min-width: 0;
}
header {
text-align: center;
margin-bottom: 4rem;
}
h1 {
font-size: 3rem;
font-weight: 800;
margin-bottom: 1rem;
background: linear-gradient(135deg, var(--primary-color) 0%, #fda4af 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 0 40px var(--primary-glow);
}
.subtitle {
font-size: 1.2rem;
color: var(--text-muted);
}
.section {
background: rgba(21, 30, 50, 0.6);
border: 1px solid var(--card-border);
border-radius: 16px;
padding: 2.5rem;
margin-bottom: 2.5rem;
box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.5);
backdrop-filter: blur(10px);
transition: transform 0.3s ease, box-shadow 0.3s ease;
scroll-margin-top: 3rem;
}
.section:hover {
transform: translateY(-5px);
box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
border-color: rgba(255, 255, 255, 0.15);
}
.divider {
text-align: center;
margin: 4rem 0;
padding: 2rem 0;
border-top: 1px dashed var(--card-border);
border-bottom: 1px dashed var(--card-border);
background: rgba(244, 63, 94, 0.05);
border-radius: 12px;
}
.divider h2 {
color: var(--primary-color);
margin: 0;
font-size: 2rem;
justify-content: center;
}
h2 {
font-size: 1.8rem;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
color: #fff;
}
h3 {
font-size: 1.3rem;
margin: 1.5rem 0 1rem;
color: #e2e8f0;
}
p {
margin-bottom: 1rem;
font-size: 1.1rem;
color: #c9d1d9;
}
/* Callouts */
.explanation {
background: rgba(244, 63, 94, 0.1);
border-left: 4px solid var(--primary-color);
padding: 1rem 1.5rem;
border-radius: 0 8px 8px 0;
margin: 1.5rem 0;
}
.tip-callout {
background: rgba(56, 189, 248, 0.1);
border-left: 4px solid #38bdf8;
padding: 1rem 1.5rem;
border-radius: 0 8px 8px 0;
margin: 1.5rem 0;
}
.explanation p, .tip-callout p {
margin-bottom: 0;
color: #e2e8f0;
}
pre {
background: #010409 !important;
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 1.5rem !important;
margin: 1.5rem 0;
overflow-x: auto;
}
code {
font-family: 'JetBrains Mono', monospace !important;
font-size: 0.95rem;
}
/* Ascii Art Diagrams */
.diagram {
font-family: 'JetBrains Mono', monospace;
background: #050505;
color: #34d399; /* Matrix green */
padding: 1.5rem;
border-radius: 12px;
border: 1px solid #10b981;
box-shadow: 0 0 20px rgba(16, 185, 129, 0.1);
overflow-x: auto;
white-space: pre;
line-height: 1.4;
margin: 1.5rem 0;
font-size: 0.9rem;
}
/* Cards */
.rule-card {
background: linear-gradient(145deg, rgba(255, 123, 114, 0.1) 0%, rgba(220, 38, 38, 0.05) 100%);
border: 1px solid rgba(255, 123, 114, 0.2);
padding: 1.5rem;
border-radius: 12px;
margin-bottom: 1rem;
}
.rule-card h4 {
color: #fca5a5;
margin-bottom: 0.5rem;
font-size: 1.2rem;
}
hr {
border: 0;
height: 1px;
background: var(--card-border);
margin: 2rem 0;
}
.cta-banner {
text-align: center;
background: linear-gradient(135deg, var(--primary-color) 0%, #4338ca 100%);
padding: 3rem 2rem;
border-radius: 16px;
margin-top: 4rem;
}
.cta-banner h2 {
justify-content: center;
margin-bottom: 1rem;
}
.cta-banner p {
color: rgba(255, 255, 255, 0.9);
margin-bottom: 0;
}
.badge {
background: var(--primary-color);
color: #fff;
padding: 0.2rem 0.6rem;
border-radius: 6px;
font-size: 0.8rem;
font-weight: 700;
vertical-align: middle;
margin-left: 0.5rem;
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
background: #334155;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--primary-color);
}
@media (max-width: 900px) {
.layout {
flex-direction: column;
}
.sidebar {
width: 100%;
position: relative;
top: 0;
max-height: none;
margin-bottom: 2rem;
}
}
</style>
</head>
<body>
<div class="layout">
<!-- Sidebar Navigation -->
<aside class="sidebar">
<h3>📚 Arch Guide</h3>
<nav>
<ul>
<li class="nav-section">The Basics</li>
<li><a href="#intro">🏢 Kya Hai System Design?</a></li>
<li><a href="#scaling">⚖️ Vertical vs Horizontal</a></li>
<li class="nav-section">Core Components</li>
<li><a href="#load-balancer">🚦 Load Balancer (LB)</a></li>
<li><a href="#caching">⚡ Caching (Redis)</a></li>
<li><a href="#databases">🗄️ Databases (SQL/NoSQL)</a></li>
<li><a href="#message-queues">📨 Message Queues (Kafka)</a></li>
<li class="nav-section">System Architecture</li>
<li><a href="#microservices">🧩 Microservices</a></li>
<li><a href="#cap-theorem">📐 CAP Theorem</a></li>
</ul>
</nav>
</aside>
<!-- Main Content -->
<main class="main-content">
<header>
<h1>System Design Architecture 🔥</h1>
<p class="subtitle">Scalable Backend Systems Aur Unka Poora Mechanism Woh Bhi Desi Style Mein 👨💻</p>
</header>
<!-- ==========================================
BASICS
=========================================== -->
<div class="section" id="intro">
<h2>🏢 1. System Design Kya Bawal Hai?</h2>
<p>Jab app pe 10 users hote hain toh ek simple Node.js server aur ek database mast chalta hai. Lekin jab Whatsapp ya Zomato banna ho (jaha 1 Crore log ek sath aayein), tab server crash ho jata hai.</p>
<div class="explanation">
<p>👉 <strong>System Design:</strong> Ek aisa architecture / blueprint tayar karna jo Kitna bhi traffic aaye handle kar le (bina crash hue, kam se kam latency pe).</p>
</div>
</div>
<div class="section" id="scaling">
<h2>⚖️ 2. Scaling (Server Bada Karna)</h2>
<p>Traffic badhne par server ko takatwar banane ke 2 tareeqe hote hain:</p>
<h3>1. Vertical Scaling (Scale UP ⬆️)</h3>
<p>Ek hi server ka RAM or CPU badha dena. (16GB RAM nikal ke 64GB laga dena).<br>
📉 <strong>Disadvantage:</strong> Ek limit hai iski (Ek machine me tu infinity RAM nahi laga sakta). Agar ye eklauti machine band hui, app down.</p>
<h3>2. Horizontal Scaling (Scale OUT ➡️)</h3>
<p>Server ka CPU badhane ki jagah, waise hi saste 10 server aur kharid lena aur traffic unme baant dena.</p>
<div class="diagram">
[User] [Server 1]
| /
|---------> [Load Balancer] ---------+---> [Server 2]
\
[Server 3]
</div>
<div class="tip-callout">
<p>💡 <strong>Rule of thumb:</strong> Modern system design hamesha Horizontal Scaling (distributed systems) par focus karta hai.</p>
</div>
</div>
<!-- ==========================================
CORE COMPONENTS
=========================================== -->
<div class="divider" id="load-balancer">
<h2>🚦 TRAFFIC COP: LOAD BALANCER</h2>
</div>
<div class="section">
<h2>🚦 3. Load Balancer (LB)</h2>
<p>Maan le tune 10 server bana diye (Horizontal Scale kar liya). Ab naya User request lekar aaya, usey kaise pata chalega ki usse konsi IP / server par jana hai?</p>
<p><strong>Load Balancer:</strong> Ye woh guard hai jo saari traffic receive karta hai aur check karta hai konsa server free hai, aur traffic waha bhej deta hai.</p>
<pre><code class="language-javascript">Tools Used: NGINX, HAProxy, AWS ALB</code></pre>
<h3>Algorithms of LB:</h3>
<ul>
<li>👉 <strong>Round Robin:</strong> Ek-ek karke sabko request divide karte jao (1st ko do, phir 2nd, phir 3rd).</li>
<li>👉 <strong>Least Connections:</strong> Jis server ke paas kaam sabse kam ho, naya order usko do.</li>
</ul>
</div>
<div class="section" id="caching">
<h2>⚡ 4. Caching System (Redis / Memcached)</h2>
<p>Database (Hard disk / SSD) se data laane me bohot time lagta hai. Agar same request baar-baar aa ri hai (Jaise IPL ka live score), toh hum directly Database se kyo poochey?</p>
<p>Hum bich me ek <strong>RAM (In-memory) storage</strong> lga dete hain jisko Cache kehte hain. RAM Super Fast hoti h!</p>
<div class="diagram">
(Hit!)
[User] ---> [Server] ----------> [CACHE (Redis / RAM)]
|
| (Miss!)
+-------------> [Database (Slow Disk)]
</div>
<div class="explanation">
<p>👉 Agar data Cache me mila (Cache Hit) -> FAST Retreval.<br>👉 Warna Database se lo aur Cache me daal do agli baar ke liye.</p>
</div>
</div>
<div class="section" id="databases">
<h2>🗄️ 5. Databases & Scaling</h2>
<p>Databases handle karne me 2 sabse badi theory hain:</p>
<h3>A. Replication (Master - Slave)</h3>
<p>Database server down hone se bachane ke liye uski copy rakhi jaati hai. <br>
✨ <strong>Master Node:</strong> Yaha sirf data WRITE (Insert/Update) hota hai.<br>
✨ <strong>Slave Nodes (Read Replicas):</strong> Ye Master ki copy (sync) banate rahte hain aur jab users ko data READ karna hota hai, tab waha se fetch kardte hain.</p>
<h3>B. Sharding (Data tod kar divide karna)</h3>
<p>Agar DB mein 100 Billion rows ka data aa jaaye (e.g. FB messages). Tab single DB crash ho jyega. Toh data ko Range (Age A-M aur N-Z) ke hisab se 2 alag Database machines me tod do.</p>
</div>
<div class="section" id="message-queues">
<h2>📨 6. Message Queues (Async Processing)</h2>
<p>Notification bhejna ya heavy video compress karna time-taking job hoti hai. Request API pe aayi aur user intezaar krta rahe toh UI block ho jayega!</p>
<p>Iss problem ko "Message Queues" (e.g. RabbitMQ, Apache Kafka, AWS SQS) solve karte hain.</p>
<div class="diagram">
[Microservice A (Producer)] ---> [ MESSAGE QUEUE ] ---> [Microservice B (Consumer)]
(Takes request instantly) (Stores Safely) (Processes in background)
</div>
<div class="explanation">
<p>👉 API ko request dalo -> Wo seedha Message Queue ko bhej ke user ko Success Response bhej degi -> Pichar background me aaram se message parse hota rahega (Like Email Sending).</p>
</div>
</div>
<!-- ==========================================
ARCHITECTURE RULES
=========================================== -->
<div class="divider" id="microservices">
<h2>🧩 ARCHITECTURE DESIGN PATTERNS</h2>
</div>
<div class="section">
<h2>🧩 7. Monolith vs Microservices</h2>
<h3>Monolith (Gud-Gobar ek jaga)</h3>
<p>Pura e-commerce system (Auth, Products, Cart, Payment) ek hi codebase (Git repo) me ek hi server pe deploy karna. Chhoti team/app k liye badhiya hai, par bada code fatne (crash) ka dar hota h (Cart server crash mtlb Payment server v band!)</p>
<h3>Microservices (Divide & Rule)</h3>
<p>Har feature ko alag service (alag repo, alag Server, alag Database) me break kardena.</p>
<div class="diagram">
/> [ Auth Service ] (Node.JS + MongoDB)
[API GW] -> [ Orders Service ] (Java Spring Boot + SQL)
\> [ Notification Service ] (Python + Redis)
</div>
<div class="tip-callout">
<p>💡 Agar Orders fat bhi jaye, phir bhi user Login karke baaki cheezein browse kar skta h. Plus, sabki apni choice of technology ho skti hai.</p>
</div>
</div>
<div class="section" id="cap-theorem">
<h2>📐 8. CAP Theorem (The Ultimate Rule)</h2>
<p>Distributed Systems mein ek universal sachchai hai (You can pick only 2 out of 3):</p>
<ul>
<li><strong>(C) Consistency:</strong> Har server par same second pe ekdam exact identical Data dikhe. (Acha bank transaction k liye)</li>
<li><strong>(A) Availability:</strong> System hamesha zinda rahe (har request ka response aaye bhale usme updated data na ho).</li>
<li><strong>(P) Partition Tolerance:</strong> Do servers ke beech connection tootne par bhi System work karta rahe.</li>
</ul>
<div class="rule-card">
<h4>✅ The Reality of CAP:</h4>
<p>Internet par network issues aate hain (so P is mandatory). Tuze <strong>CP (Consistency+Partition)</strong> ya <strong>AP (Availability+Partition)</strong> me choice lni hoti hai. Zomato jaisi system availability choose karegi, Banking systems Consistency choose krte hain delays ke bawajood.</p>
</div>
</div>
<div class="cta-banner">
<h2>Architect Level Unlocked! 🧠</h2>
<p>System Design koi fixed code nahi hoti, ek methodology hai scalability sochnay ki. Inhi blocks ko apnee requirements ke hisab se set kiya jata hai!! <br><br>
<strong>Keep Scaling Your Apps! 🔥🚀</strong>
</p>
</div>
</main>
</div>
</body>
</html>