-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloud.html
More file actions
1950 lines (1710 loc) · 84.7 KB
/
cloud.html
File metadata and controls
1950 lines (1710 loc) · 84.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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cloud & Infrastructure - Better Dev</title>
<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=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="topbar">
<button class="sidebar-toggle" aria-label="Open navigation" aria-expanded="false">
<span class="hamburger-icon"></span>
</button>
<a href="index.html" class="logo">Better Dev</a>
</header>
<div class="sidebar-backdrop" aria-hidden="true"></div>
<aside class="sidebar" aria-label="Site navigation">
<div class="sidebar-header">
<span class="sidebar-title">Navigation</span>
<button class="sidebar-close" aria-label="Close navigation">×</button>
</div>
<div class="sidebar-search">
<input type="text" class="sidebar-search-input" placeholder="Search topics..." aria-label="Search topics">
<div class="sidebar-search-results"></div>
</div>
<nav class="sidebar-nav">
<div class="sidebar-group">
<a href="index.html">Home</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Mathematics</div>
<a href="pre-algebra.html">Pre-Algebra</a>
<a href="algebra.html">Algebra</a>
<a href="sequences-series.html">Sequences & Series</a>
<a href="geometry.html">Geometry</a>
<a href="calculus.html">Calculus</a>
<a href="discrete-math.html">Discrete Math</a>
<a href="linear-algebra.html">Linear Algebra</a>
<a href="probability.html">Probability & Statistics</a>
<a href="binary-systems.html">Binary & Number Systems</a>
<a href="number-theory.html">Number Theory for CP</a>
<a href="computational-geometry.html">Computational Geometry</a>
<a href="game-theory.html">Game Theory</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Data Structures & Algorithms</div>
<a href="dsa-foundations.html">DSA Foundations</a>
<a href="arrays.html">Arrays & Strings</a>
<a href="stacks-queues.html">Stacks & Queues</a>
<a href="hashmaps.html">Hash Maps & Sets</a>
<a href="linked-lists.html">Linked Lists</a>
<a href="trees.html">Trees & BST</a>
<a href="graphs.html">Graphs</a>
<a href="sorting.html">Sorting & Searching</a>
<a href="patterns.html">LeetCode Patterns</a>
<a href="dp.html">Dynamic Programming</a>
<a href="advanced.html">Advanced Topics</a>
<a href="string-algorithms.html">String Algorithms</a>
<a href="advanced-graphs.html">Advanced Graphs</a>
<a href="advanced-dp.html">Advanced DP</a>
<a href="advanced-ds.html">Advanced Data Structures</a>
<a href="leetcode-650.html">The 650 Problems</a>
<a href="competitive-programming.html">CP Roadmap</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Languages & Systems</div>
<a href="cpp.html">C++</a>
<a href="golang.html">Go</a>
<a href="javascript.html">JavaScript Deep Dive</a>
<a href="typescript.html">TypeScript</a>
<a href="nodejs.html">Node.js Internals</a>
<a href="os.html">Operating Systems</a>
<a href="linux.html">Linux</a>
<a href="git.html">Git</a>
<a href="backend.html">Backend</a>
<a href="system-design.html">System Design</a>
<a href="networking.html">Networking</a>
<a href="cloud.html">Cloud & Infrastructure</a>
<a href="docker.html">Docker & Compose</a>
<a href="kubernetes.html">Kubernetes</a>
<a href="message-queues.html">Queues & Pub/Sub</a>
<a href="selfhosting.html">VPS & Self-Hosting</a>
<a href="databases.html">PostgreSQL & MySQL</a>
<a href="stripe.html">Stripe & Payments</a>
<a href="distributed-systems.html">Distributed Systems</a>
<a href="backend-engineering.html">Backend Engineering</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">JS/TS Ecosystem</div>
<a href="js-tooling.html">Tooling & Bundlers</a>
<a href="js-testing.html">Testing</a>
<a href="ts-projects.html">Building with TS</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">More</div>
<a href="seans-brain.html">Sean's Brain</a>
</div>
</nav>
</aside>
<div class="container">
<!-- ===== PAGE HEADER ===== -->
<div class="page-header">
<div class="breadcrumb"><a href="index.html">Home</a> / Cloud & Infrastructure</div>
<h1>Cloud & Infrastructure</h1>
<p>Everything you need to understand about cloud computing -- what it actually is, why it exists, how the major providers compare, and the core services that power every modern application. No marketing fluff, just the concepts and practical knowledge you need to deploy, scale, and operate real software.</p>
</div>
<!-- ===== TABLE OF CONTENTS ===== -->
<div class="toc">
<h4>Table of Contents</h4>
<a href="#what-is-cloud">1. What Is "The Cloud"?</a>
<a href="#cloud-providers">2. Cloud Providers (AWS, GCP, Azure)</a>
<a href="#core-services">3. Core Cloud Services</a>
<a href="#service-models">4. IaaS vs PaaS vs SaaS vs FaaS</a>
<a href="#serverless">5. Serverless</a>
<a href="#cicd">6. CI/CD (Continuous Integration & Deployment)</a>
<a href="#iac">7. Infrastructure as Code</a>
<a href="#load-balancers">8. Load Balancers</a>
<a href="#cdns">9. CDNs (Content Delivery Networks)</a>
<a href="#object-storage">10. Object Storage</a>
<a href="#managed-databases">11. Managed Databases</a>
<a href="#cloud-costs">12. Cloud Costs & Avoiding Bill Shock</a>
</div>
<!-- ============================================================ -->
<!-- SECTION 1: WHAT IS THE CLOUD -->
<!-- ============================================================ -->
<section id="what-is-cloud">
<h2>1. What Is "The Cloud"?</h2>
<p>Strip away all the marketing, and "the cloud" is just <strong>other people's computers that you rent</strong>. That's it. When you deploy your app to AWS, your code runs on a physical server sitting in a warehouse (called a data center) owned by Amazon. You don't buy the server. You don't maintain the server. You pay for how much you use.</p>
<div class="example-box">
<div class="label">The Restaurant Analogy</div>
<p>Running your own servers is like <strong>owning a restaurant</strong>. You buy the building, install the kitchen, hire staff, handle plumbing when it breaks, pay rent even when nobody is eating. It's total control but total responsibility.</p>
<p>Using the cloud is like <strong>renting a commercial kitchen</strong>. You show up, cook your food, serve your customers, and leave. Someone else handles the building, the electricity, the fire suppression system, and the plumbing. You just pay for the time and space you use.</p>
<p>The tradeoff: you give up some control (you can't knock out a wall to expand), but you gain speed (start cooking tomorrow, not in 6 months after construction) and flexibility (rent a bigger kitchen next month if business grows).</p>
</div>
<h3>What Does a Data Center Actually Look Like?</h3>
<p>A data center is a massive building full of racks of servers, connected by fiber optic cables, cooled by industrial HVAC systems, and backed by redundant power supplies (including diesel generators for when the grid fails). AWS alone operates 100+ data centers worldwide. Each one looks like this:</p>
<pre><code> DATA CENTER
+-------------------------------------------------+
| |
| +-------+ +-------+ +-------+ +-------+ |
| | Rack | | Rack | | Rack | | Rack | |
| |Server1| |Server1| |Server1| |Server1| |
| |Server2| |Server2| |Server2| |Server2| |
| |Server3| |Server3| |Server3| |Server3| |
| | ... | | ... | | ... | | ... | |
| +---+---+ +---+---+ +---+---+ +---+---+ |
| | | | | |
| +---+----------+----------+----------+---+ |
| | Network Switch Layer | |
| +---+------------------------------------+ |
| | |
| +---+---+ +----------+ +-----------+ |
| |Router | | Cooling | | Backup | |
| |to ISP | | System | | Power | |
| +-------+ +----------+ +-----------+ |
| |
+-------------------------------------------------+
|
To the internet (your users)</code></pre>
<h3>Why the Cloud Exists</h3>
<p>Before the cloud, if you wanted to launch a web app, you had to:</p>
<ul>
<li><strong>Buy physical servers</strong> -- $5,000-$50,000 per machine, weeks of lead time</li>
<li><strong>Rent rack space</strong> in a data center (or build your own)</li>
<li><strong>Hire sysadmins</strong> to maintain hardware, replace failed disks, patch OSes</li>
<li><strong>Guess your capacity</strong> -- buy too few servers and you crash on launch day, buy too many and you waste money</li>
<li><strong>Handle disasters</strong> -- what happens when a server catches fire? When the building floods?</li>
</ul>
<p>The cloud eliminates all of this. You click a button (or run a command), and a virtual server appears in seconds. Need 10 more? Click 10 more times. Traffic drops? Turn them off and stop paying. This is <strong>elastic computing</strong>, and it changed how software is built.</p>
<div class="tip-box">
<div class="label">Key Cloud Concepts</div>
<ul>
<li><strong>On-demand:</strong> Get resources instantly, pay as you go</li>
<li><strong>Elastic:</strong> Scale up when you need more, scale down when you don't</li>
<li><strong>Regions:</strong> Data centers in different geographic locations (us-east-1, eu-west-1, ap-southeast-1). Deploy close to your users for lower latency.</li>
<li><strong>Availability Zones (AZs):</strong> Separate physical buildings within a region. If one AZ loses power, your app stays up in another AZ.</li>
<li><strong>Multi-region:</strong> Deploy in multiple regions for global coverage and disaster recovery</li>
</ul>
</div>
<div class="warning-box">
<div class="label">The Cloud Is Not Magic</div>
<p>Your code still runs on physical hardware. Hard drives still fail. Networks still have latency. Servers still crash. The cloud doesn't eliminate infrastructure problems -- it makes them <em>someone else's problem</em> and gives you tools to handle failures gracefully (redundancy, auto-scaling, health checks). But if you design your app assuming nothing ever fails, you'll have a bad time, cloud or not.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 2: CLOUD PROVIDERS -->
<!-- ============================================================ -->
<section id="cloud-providers">
<h2>2. Cloud Providers (AWS, GCP, Azure)</h2>
<p>Three companies dominate cloud computing: <strong>AWS</strong> (Amazon), <strong>Azure</strong> (Microsoft), and <strong>GCP</strong> (Google). Together they hold about 65% of the market. There are also strong alternatives: DigitalOcean, Linode (now Akamai), Hetzner, Vultr, and Cloudflare.</p>
<h3>The Big Three Compared</h3>
<table>
<tr>
<th>Aspect</th>
<th>AWS</th>
<th>GCP</th>
<th>Azure</th>
</tr>
<tr>
<td>Market share</td>
<td>~31% (largest)</td>
<td>~12%</td>
<td>~25%</td>
</tr>
<tr>
<td>Best for</td>
<td>Everything. Most services, most mature.</td>
<td>Data/ML, Kubernetes, developer UX</td>
<td>Enterprise, Windows/.NET, Office 365 integration</td>
</tr>
<tr>
<td>Compute</td>
<td>EC2</td>
<td>Compute Engine</td>
<td>Virtual Machines</td>
</tr>
<tr>
<td>Object Storage</td>
<td>S3</td>
<td>Cloud Storage</td>
<td>Blob Storage</td>
</tr>
<tr>
<td>Serverless</td>
<td>Lambda</td>
<td>Cloud Functions</td>
<td>Azure Functions</td>
</tr>
<tr>
<td>Managed K8s</td>
<td>EKS</td>
<td>GKE (best K8s experience)</td>
<td>AKS</td>
</tr>
<tr>
<td>Managed DB</td>
<td>RDS, DynamoDB, Aurora</td>
<td>Cloud SQL, Spanner, Firestore</td>
<td>Azure SQL, Cosmos DB</td>
</tr>
<tr>
<td>CDN</td>
<td>CloudFront</td>
<td>Cloud CDN</td>
<td>Azure CDN</td>
</tr>
<tr>
<td>Free tier</td>
<td>12-month free tier + always-free tier</td>
<td>$300 credit for 90 days + always-free tier</td>
<td>$200 credit for 30 days + always-free tier</td>
</tr>
<tr>
<td>CLI</td>
<td><code>aws</code></td>
<td><code>gcloud</code></td>
<td><code>az</code></td>
</tr>
<tr>
<td>Pricing</td>
<td>Complex, many hidden costs</td>
<td>Simpler, per-second billing</td>
<td>Complex, enterprise-oriented</td>
</tr>
<tr>
<td>Learning curve</td>
<td>Steepest -- 200+ services</td>
<td>Moderate -- cleaner console</td>
<td>Moderate -- if you know Microsoft ecosystem</td>
</tr>
</table>
<div class="tip-box">
<div class="label">Which One Should You Learn?</div>
<p><strong>For jobs:</strong> Learn AWS. It has the most market share, the most job listings, and the most services. Knowing AWS makes you employable almost anywhere.</p>
<p><strong>For startups:</strong> GCP often has the best developer experience and generous free tiers. Their Kubernetes offering (GKE) is best-in-class since Google invented Kubernetes.</p>
<p><strong>For enterprise:</strong> If the company already uses Microsoft (Active Directory, Office 365, .NET), Azure is the natural choice because of deep integration.</p>
<p><strong>For personal projects:</strong> DigitalOcean, Hetzner, or Vultr. Simpler, cheaper, and you'll learn more about infrastructure because there's less hand-holding.</p>
</div>
<h3>Service Name Rosetta Stone</h3>
<p>Every provider has the same core services -- they just give them different names. Here's how to translate:</p>
<table>
<tr>
<th>What You Need</th>
<th>AWS</th>
<th>GCP</th>
<th>Azure</th>
</tr>
<tr>
<td>Virtual server</td>
<td>EC2</td>
<td>Compute Engine</td>
<td>Virtual Machines</td>
</tr>
<tr>
<td>Object storage</td>
<td>S3</td>
<td>Cloud Storage</td>
<td>Blob Storage</td>
</tr>
<tr>
<td>SQL database</td>
<td>RDS</td>
<td>Cloud SQL</td>
<td>Azure SQL</td>
</tr>
<tr>
<td>NoSQL database</td>
<td>DynamoDB</td>
<td>Firestore</td>
<td>Cosmos DB</td>
</tr>
<tr>
<td>Serverless functions</td>
<td>Lambda</td>
<td>Cloud Functions</td>
<td>Azure Functions</td>
</tr>
<tr>
<td>Container orchestration</td>
<td>ECS / EKS</td>
<td>Cloud Run / GKE</td>
<td>ACI / AKS</td>
</tr>
<tr>
<td>Message queue</td>
<td>SQS</td>
<td>Pub/Sub</td>
<td>Service Bus</td>
</tr>
<tr>
<td>DNS</td>
<td>Route 53</td>
<td>Cloud DNS</td>
<td>Azure DNS</td>
</tr>
<tr>
<td>Secret management</td>
<td>Secrets Manager</td>
<td>Secret Manager</td>
<td>Key Vault</td>
</tr>
<tr>
<td>IAM (permissions)</td>
<td>IAM</td>
<td>IAM</td>
<td>Entra ID (was Azure AD)</td>
</tr>
</table>
</section>
<!-- ============================================================ -->
<!-- SECTION 3: CORE CLOUD SERVICES -->
<!-- ============================================================ -->
<section id="core-services">
<h2>3. Core Cloud Services</h2>
<p>Every cloud provider offers hundreds of services, but you only need to understand about 5-6 core ones to be productive. Everything else is built on top of these fundamentals.</p>
<h3>Compute (EC2 / VMs)</h3>
<p>A virtual machine in the cloud. You choose the CPU, RAM, and disk size. You get root access. It's like having a remote computer you can SSH into. This is the most fundamental cloud service -- everything else can theoretically run on a VM.</p>
<pre><code># Launch an EC2 instance (AWS CLI)
aws ec2 run-instances \
--image-id ami-0c55b159cbfafe1f0 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-0123456789abcdef0
# SSH into it
ssh -i my-key-pair.pem ec2-user@54.123.45.67
# Common instance types (AWS):
# t3.micro -- 2 vCPU, 1 GB RAM -- free tier, dev/test
# t3.medium -- 2 vCPU, 4 GB RAM -- small apps
# m6i.large -- 2 vCPU, 8 GB RAM -- general purpose
# c6i.large -- 2 vCPU, 4 GB RAM -- CPU-intensive (compute-optimized)
# r6i.large -- 2 vCPU, 16 GB RAM -- memory-intensive (databases, caching)</code></pre>
<div class="tip-box">
<div class="label">Instance Type Naming (AWS)</div>
<p>The naming follows a pattern: <code>t3.micro</code> = <strong>t</strong> (family: burstable) + <strong>3</strong> (generation) + <strong>micro</strong> (size). Families: <strong>t</strong> = burstable (cheap, good for variable workloads), <strong>m</strong> = general purpose, <strong>c</strong> = compute-optimized, <strong>r</strong> = memory-optimized, <strong>g/p</strong> = GPU instances.</p>
</div>
<h3>Storage (S3 / Blob)</h3>
<p>Object storage for files of any size -- images, videos, backups, logs, static websites. You upload objects into "buckets" (containers). Each object gets a unique key (like a file path). S3 has 99.999999999% (eleven 9s) durability -- meaning if you store 10 million objects, you might lose 1 every 10,000 years.</p>
<pre><code># Upload a file to S3
aws s3 cp ./backup.tar.gz s3://my-bucket/backups/backup-2024-01-15.tar.gz
# List bucket contents
aws s3 ls s3://my-bucket/backups/
# Download a file
aws s3 cp s3://my-bucket/backups/backup-2024-01-15.tar.gz ./
# Sync a directory (like rsync)
aws s3 sync ./dist s3://my-website-bucket/ --delete</code></pre>
<h3>Databases (RDS)</h3>
<p>Managed database services. You pick the engine (PostgreSQL, MySQL, etc.) and the instance size. The cloud provider handles backups, patching, replication, and failover. You just connect and run queries.</p>
<pre><code># What "managed" means -- the provider handles:
# - Automated daily backups (point-in-time recovery)
# - OS and database engine patching
# - Multi-AZ failover (automatic switch to standby if primary dies)
# - Read replicas (for scaling reads)
# - Monitoring and alerts
# - Storage auto-scaling
# You handle:
# - Schema design
# - Query optimization
# - Application-level connection pooling
# - Access control (who can connect)</code></pre>
<h3>Networking (VPC)</h3>
<p>A <strong>Virtual Private Cloud</strong> is your own private network in the cloud. It's like having your own isolated section of the data center. You control which resources can talk to each other, which can access the internet, and which ports are open.</p>
<pre><code> YOUR VPC (10.0.0.0/16)
+---------------------------------------------------+
| |
| Public Subnet (10.0.1.0/24) |
| +---------------------------------------------+ |
| | Load Balancer ---> Web Server (EC2) | |
| +---------------------------------------------+ |
| | |
| Private Subnet (10.0.2.0/24) |
| +---------------------------------------------+ |
| | App Server (EC2) ---> Database (RDS) | |
| +---------------------------------------------+ |
| |
+---------------------------------------------------+
|
Internet Gateway (only public subnet has access)</code></pre>
<div class="example-box">
<div class="label">Why VPC Matters</div>
<p>Without a VPC, your database would be directly accessible from the internet. Anyone could try to connect. With a VPC, your database sits in a <strong>private subnet</strong> with no internet access. Only your app servers in the same VPC can reach it. The load balancer sits in a <strong>public subnet</strong> and forwards traffic to the app servers. This is defense in depth -- even if someone compromises your web server, they can't directly access the database from outside.</p>
</div>
<h3>CDN (CloudFront / Cloud CDN)</h3>
<p>A Content Delivery Network caches your content at <strong>edge locations</strong> around the world. When a user in Tokyo requests your image, they get it from a server in Tokyo instead of your origin server in Virginia. This reduces latency from ~200ms to ~20ms. More on this in <a href="#cdns">Section 9</a>.</p>
</section>
<!-- ============================================================ -->
<!-- SECTION 4: SERVICE MODELS -->
<!-- ============================================================ -->
<section id="service-models">
<h2>4. IaaS vs PaaS vs SaaS vs FaaS</h2>
<p>These acronyms describe <strong>how much the provider manages for you</strong>. Think of it as a spectrum from "you manage everything" to "you manage nothing".</p>
<pre><code> What YOU manage vs what the PROVIDER manages:
On-Premise IaaS PaaS FaaS SaaS
(you own (rent (rent (rent (rent
everything) hardware) platform) functions) software)
+----------+ +----------+ +----------+ +----------+ +----------+
| App | | App | | App | | Function | | |
+----------+ +----------+ +----------+ +----------+ | |
| Runtime | | Runtime | |##########| |##########| | |
+----------+ +----------+ +----------+ +----------+ | Gmail |
| OS | | OS | |##########| |##########| | Slack |
+----------+ +----------+ +----------+ +----------+ | Shopify |
| Disk | |##########| |##########| |##########| | |
+----------+ +----------+ +----------+ +----------+ | |
| Network | |##########| |##########| |##########| | |
+----------+ +----------+ +----------+ +----------+ +----------+
[ = You manage ] [## = Provider manages ]</code></pre>
<h3>IaaS -- Infrastructure as a Service</h3>
<p>You rent the hardware (virtual machines, networking, storage). You install and manage everything on top: the OS, runtime, app, security patches.</p>
<p><strong>Examples:</strong> AWS EC2, GCP Compute Engine, DigitalOcean Droplets, Hetzner Cloud</p>
<p><strong>Use when:</strong> You need full control. Custom OS configurations. Running software that doesn't fit into platform constraints. You have the ops expertise to manage it.</p>
<div class="example-box">
<div class="label">IaaS in Practice</div>
<pre><code># You spin up a VM, then you're responsible for everything:
ssh root@your-server
apt update && apt upgrade # You patch the OS
apt install nodejs nginx postgresql # You install dependencies
git clone your-repo && npm install # You deploy your code
systemctl enable nginx # You configure the web server
certbot --nginx # You manage SSL certificates
# ...and you set up monitoring, backups, firewalls, log rotation</code></pre>
</div>
<h3>PaaS -- Platform as a Service</h3>
<p>You give the provider your code, and they handle the rest -- servers, OS, runtime, scaling, SSL, deployments. You just <code>git push</code>.</p>
<p><strong>Examples:</strong> Heroku, Vercel, Netlify, Railway, Render, Fly.io, Google App Engine</p>
<p><strong>Use when:</strong> You want to ship fast without managing infrastructure. Small teams. Prototypes. Apps that fit standard patterns.</p>
<div class="example-box">
<div class="label">PaaS in Practice</div>
<pre><code># Heroku: deploy a Node.js app
git push heroku main
# That's it. Heroku detects Node.js, installs dependencies,
# starts your server, gives you a URL, handles SSL, and scales.
# Vercel: deploy a Next.js app
vercel --prod
# Builds, deploys to edge network, SSL, custom domain, done.
# Railway: deploy anything with a Dockerfile
railway up
# Detects Dockerfile, builds, deploys, gives you a URL.</code></pre>
</div>
<h3>SaaS -- Software as a Service</h3>
<p>You don't manage anything. You just use the software through a browser or API. The provider handles everything -- infrastructure, updates, security, availability.</p>
<p><strong>Examples:</strong> Gmail, Slack, Shopify, GitHub, Notion, Stripe, Twilio</p>
<p><strong>Use when:</strong> The software does what you need out of the box. You're a user, not a builder (for that specific function).</p>
<h3>FaaS -- Functions as a Service</h3>
<p>You write individual functions. The provider runs them when triggered (HTTP request, file upload, timer, queue message). No servers to manage. You pay per execution, not per hour. More on this in <a href="#serverless">Section 5</a>.</p>
<p><strong>Examples:</strong> AWS Lambda, Google Cloud Functions, Cloudflare Workers, Azure Functions</p>
<table>
<tr>
<th>Model</th>
<th>You Manage</th>
<th>Provider Manages</th>
<th>Cost Model</th>
<th>Best For</th>
</tr>
<tr>
<td><strong>IaaS</strong></td>
<td>OS, runtime, app, data</td>
<td>Hardware, network, storage</td>
<td>Per hour/second (VM runs)</td>
<td>Full control, custom setups</td>
</tr>
<tr>
<td><strong>PaaS</strong></td>
<td>App, data</td>
<td>Everything else</td>
<td>Per dyno/instance + usage</td>
<td>Fast deployment, small teams</td>
</tr>
<tr>
<td><strong>FaaS</strong></td>
<td>Individual functions</td>
<td>Everything else</td>
<td>Per invocation + duration</td>
<td>Event-driven, sporadic workloads</td>
</tr>
<tr>
<td><strong>SaaS</strong></td>
<td>Configuration, data</td>
<td>Everything</td>
<td>Per user/month or per usage</td>
<td>Standard business tools</td>
</tr>
</table>
<div class="warning-box">
<div class="label">The PaaS Trap</div>
<p>PaaS is amazing for getting started but can become expensive at scale. Heroku's free tier is gone, and a basic production setup (2 dynos + managed Postgres + Redis) can run $100+/month -- the same workload on a $20/month VPS. Many startups start on PaaS for speed, then migrate to IaaS or containers as they grow. Plan for this migration path from day one.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 5: SERVERLESS -->
<!-- ============================================================ -->
<section id="serverless">
<h2>5. Serverless</h2>
<p>Serverless is the most misnamed concept in computing. There <em>are</em> servers -- you just don't think about them. You write a function, upload it, and the cloud provider runs it whenever it's triggered. You don't provision VMs, you don't manage scaling, you don't patch anything. You pay only when your code actually runs.</p>
<div class="example-box">
<div class="label">The Vending Machine Analogy</div>
<p>A traditional server is like <strong>a restaurant kitchen</strong>: it's running all the time, waiting for orders, costing money even when nobody is eating. A serverless function is like a <strong>vending machine</strong>: it does nothing until someone presses a button. It serves the request, then goes idle. You don't pay for idle time.</p>
</div>
<h3>AWS Lambda Example</h3>
<pre><code>// handler.js -- an AWS Lambda function
// This function runs when triggered (HTTP request, S3 upload, etc.)
exports.handler = async (event) => {
// event contains the trigger data (request body, S3 event, etc.)
const name = event.queryStringParameters?.name || "World";
return {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: `Hello, ${name}!`,
timestamp: new Date().toISOString(),
}),
};
};
// Deploy with AWS CLI:
// aws lambda create-function \
// --function-name hello \
// --runtime nodejs20.x \
// --handler handler.handler \
// --zip-file fileb://function.zip \
// --role arn:aws:iam::123456789:role/lambda-role</code></pre>
<h3>Cloudflare Workers Example</h3>
<pre><code>// worker.js -- runs at the edge (200+ locations worldwide)
// Response time: ~10ms because it runs near the user
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname === "/api/hello") {
return new Response(JSON.stringify({ message: "Hello from the edge!" }), {
headers: { "Content-Type": "application/json" },
});
}
return new Response("Not Found", { status: 404 });
},
};
// Deploy: wrangler deploy</code></pre>
<h3>Cold Starts -- The Serverless Tax</h3>
<p>When a serverless function hasn't been called recently, the provider needs to spin up a new execution environment (load your code, initialize the runtime, run your initialization code). This is called a <strong>cold start</strong>, and it adds latency to the first request.</p>
<table>
<tr>
<th>Runtime</th>
<th>Cold Start Time</th>
<th>Notes</th>
</tr>
<tr>
<td>Node.js</td>
<td>100-500ms</td>
<td>Fast, good default choice</td>
</tr>
<tr>
<td>Python</td>
<td>200-600ms</td>
<td>Depends on imports (numpy is heavy)</td>
</tr>
<tr>
<td>Go</td>
<td>50-200ms</td>
<td>Compiled binary, fastest cold starts</td>
</tr>
<tr>
<td>Java</td>
<td>1-5 seconds</td>
<td>JVM startup is heavy; use GraalVM to improve</td>
</tr>
<tr>
<td>Cloudflare Workers</td>
<td><5ms</td>
<td>V8 isolates, not containers -- nearly instant</td>
</tr>
</table>
<div class="tip-box">
<div class="label">Reducing Cold Starts</div>
<ul>
<li><strong>Provisioned concurrency (Lambda):</strong> Keep N instances warm. Costs more but eliminates cold starts.</li>
<li><strong>Small bundles:</strong> Less code to load = faster cold start. Tree-shake your dependencies.</li>
<li><strong>Avoid heavy imports:</strong> Don't import the entire AWS SDK when you only need S3.</li>
<li><strong>Use compiled languages:</strong> Go has the fastest cold starts. Rust is also excellent.</li>
<li><strong>Edge runtimes:</strong> Cloudflare Workers, Deno Deploy, and Vercel Edge Functions use V8 isolates instead of containers. Cold starts are near-zero.</li>
</ul>
</div>
<h3>When to Use Serverless (and When NOT To)</h3>
<table>
<tr>
<th>Good Fit</th>
<th>Bad Fit</th>
</tr>
<tr>
<td>API endpoints with variable traffic</td>
<td>Long-running processes (>15 min)</td>
</tr>
<tr>
<td>Event processing (file uploads, webhooks)</td>
<td>WebSocket connections</td>
</tr>
<tr>
<td>Scheduled tasks (cron jobs)</td>
<td>Stateful applications</td>
</tr>
<tr>
<td>Image/video processing triggers</td>
<td>High-throughput, consistent traffic</td>
</tr>
<tr>
<td>Low-traffic APIs (pay $0 when idle)</td>
<td>Applications needing <10ms latency on every request</td>
</tr>
<tr>
<td>MVP / prototypes (ship fast, worry later)</td>
<td>Complex apps with many interconnected services</td>
</tr>
</table>
<div class="warning-box">
<div class="label">The Serverless Cost Crossover</div>
<p>Serverless is cheap for low traffic (you pay nothing when idle). But at high, consistent traffic, it gets expensive. A Lambda function handling 10 million requests/month with 500ms average duration costs roughly $30-50/month. That same workload on a $5/month VPS would handle it easily. Serverless is cheaper below a threshold and more expensive above it. That crossover point varies, but for many apps it's around 1-5 million requests/month.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 6: CI/CD -->
<!-- ============================================================ -->
<section id="cicd">
<h2>6. CI/CD (Continuous Integration & Deployment)</h2>
<p>CI/CD automates the process of testing, building, and deploying your code. Without it, deployments are manual, error-prone, and scary. With it, you push code to Git and it automatically gets tested and deployed. This is how professional teams ship software.</p>
<div class="example-box">
<div class="label">What CI and CD Actually Mean</div>
<p><strong>Continuous Integration (CI):</strong> Every time you push code, automated tests run. If tests fail, the build fails and you know immediately. This catches bugs before they reach production. The "continuous" part means it happens on every push, not once a week.</p>
<p><strong>Continuous Delivery (CD):</strong> After CI passes, the code is automatically packaged and ready to deploy. A human clicks "deploy" to push to production.</p>
<p><strong>Continuous Deployment (also CD):</strong> After CI passes, the code automatically deploys to production with no human intervention. This is what most modern teams aim for.</p>
</div>
<pre><code> Developer pushes code to GitHub
|
v
+--------------------+
| CI Pipeline Runs | (automated)
| - Install deps |
| - Lint code |
| - Run tests |
| - Build project |
+---------+----------+
|
Tests pass?
/ \
YES NO
| |
v v
+--------+ +----------+
| Deploy | | Notify |
| to | | developer|
| prod | | (fix it) |
+--------+ +----------+</code></pre>
<h3>GitHub Actions -- The Most Common CI/CD Tool</h3>
<p>GitHub Actions runs workflows defined in YAML files inside your repo (<code>.github/workflows/</code>). Workflows are triggered by events (push, pull request, schedule, manual). Each workflow has jobs, and each job has steps.</p>
<pre><code># .github/workflows/ci.yml
name: CI/CD Pipeline
# When to run
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest # GitHub provides the VM
steps:
# 1. Check out your code
- uses: actions/checkout@v4
# 2. Set up Node.js
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm' # Cache node_modules between runs
# 3. Install dependencies
- run: npm ci
# 4. Lint
- run: npm run lint
# 5. Run tests
- run: npm test
# 6. Build
- run: npm run build
deploy:
needs: test # Only runs if "test" job passes
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only deploy from main branch
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run build
# Deploy to your hosting provider
- name: Deploy to production
run: |
npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}</code></pre>
<div class="example-box">
<div class="label">Line-by-Line Breakdown</div>
<p><code>on: push/pull_request</code> -- Trigger this workflow when someone pushes to main or opens a PR against main.</p>
<p><code>runs-on: ubuntu-latest</code> -- GitHub spins up a fresh Ubuntu VM for this job. It's destroyed after the job finishes. You get 2,000 free minutes/month on the free plan.</p>
<p><code>uses: actions/checkout@v4</code> -- A pre-built action that clones your repo into the VM. Without this, the VM has no code.</p>
<p><code>cache: 'npm'</code> -- Caches <code>node_modules</code> between workflow runs. Instead of downloading all dependencies every time (30-60 seconds), it restores from cache (2-3 seconds).</p>
<p><code>needs: test</code> -- The deploy job won't start until the test job succeeds. If tests fail, deploy is skipped.</p>
<p><code>${{ secrets.VERCEL_TOKEN }}</code> -- GitHub Secrets store sensitive values (API keys, tokens). You set them in your repo settings. They're never exposed in logs.</p>
</div>
<h3>A Real-World Workflow: Docker Build + Deploy</h3>
<pre><code># .github/workflows/deploy.yml
name: Build and Deploy
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Log into Docker Hub (or ECR, GHCR)
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
# Build and push Docker image
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: myuser/myapp:latest,myuser/myapp:${{ github.sha }}
# Deploy to server via SSH
- name: Deploy
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: deploy
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker pull myuser/myapp:latest
docker stop myapp || true
docker rm myapp || true
docker run -d --name myapp \
-p 80:3000 \
--env-file /home/deploy/.env \
myuser/myapp:latest</code></pre>
<div class="tip-box">
<div class="label">CI/CD Best Practices</div>
<ul>
<li><strong>Run tests on every PR</strong> -- Never merge code that breaks tests</li>
<li><strong>Keep pipelines fast</strong> -- Under 5 minutes is ideal. Cache dependencies aggressively.</li>
<li><strong>Use branch protection</strong> -- Require CI to pass before merging to main</li>
<li><strong>Never put secrets in code</strong> -- Use GitHub Secrets, environment variables, or a vault</li>
<li><strong>Tag deployments</strong> -- Use git SHA or semver tags so you can roll back to any version</li>
<li><strong>Monitor after deploy</strong> -- Set up alerts for error rates, response times, and health checks</li>
</ul>
</div>
<div class="warning-box">
<div class="label">Other CI/CD Tools</div>
<p>GitHub Actions is the most popular for open source and startups. But you'll also encounter: <strong>GitLab CI</strong> (built into GitLab), <strong>Jenkins</strong> (self-hosted, oldest, most configurable), <strong>CircleCI</strong>, <strong>Travis CI</strong> (declining), <strong>Buildkite</strong> (hybrid -- you provide the runners), and <strong>Drone CI</strong> (container-native). The concepts are identical across all of them -- only the YAML syntax differs.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 7: INFRASTRUCTURE AS CODE -->
<!-- ============================================================ -->
<section id="iac">
<h2>7. Infrastructure as Code</h2>
<p>Infrastructure as Code (IaC) means defining your cloud resources in code files instead of clicking through a web console. Your servers, databases, networks, DNS records -- all described in text files that live in Git. This makes infrastructure reproducible, reviewable, and version-controlled.</p>
<div class="example-box">
<div class="label">Why IaC Matters</div>
<p>Imagine you set up your production environment by clicking through the AWS console for 3 hours. Everything works. Six months later, you need to create an identical staging environment. Can you remember every click? Every security group rule? Every IAM policy? Of course not.</p>
<p>With IaC, you run <code>terraform apply</code> and your entire infrastructure is created from a file. Need a staging copy? Change a variable and apply again. Need to see who changed the database size? Check the git log. Need to roll back a networking change? <code>git revert</code> and re-apply.</p>
</div>
<h3>Declarative vs Imperative</h3>
<pre><code># IMPERATIVE (scripts): "Here are the steps to get there"
# Like giving someone turn-by-turn directions
aws ec2 create-security-group --group-name web-sg --description "Web SG"
aws ec2 authorize-security-group-ingress --group-name web-sg --port 80 --cidr 0.0.0.0/0
aws ec2 run-instances --instance-type t3.micro --security-groups web-sg
# Problem: run it twice and you get TWO servers. Not idempotent.
# DECLARATIVE (Terraform/CloudFormation): "Here's what I want to exist"
# Like showing someone a photo of where you want to go
resource "aws_instance" "web" {
instance_type = "t3.micro"
ami = "ami-0c55b159cbfafe1f0"
}
# Run it twice and Terraform says "already exists, nothing to do."
# Change instance_type and Terraform updates only what changed.</code></pre>
<h3>Terraform -- The Most Popular IaC Tool</h3>
<p>Terraform by HashiCorp works with every cloud provider (and many other services like GitHub, Cloudflare, Datadog). You write <code>.tf</code> files using HCL (HashiCorp Configuration Language), then Terraform figures out what needs to be created, updated, or destroyed.</p>
<pre><code># main.tf -- Define your infrastructure
# Tell Terraform which providers to use
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
# Configure the AWS provider
provider "aws" {
region = "us-east-1"
}
# Create a VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "my-app-vpc"
}
}
# Create a public subnet
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
tags = {
Name = "public-subnet"
}
}
# Create an EC2 instance
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = var.instance_type # Variable -- configurable
subnet_id = aws_subnet.public.id # Reference another resource
tags = {
Name = "web-server"
Environment = var.environment
}
}
# Create an RDS database
resource "aws_db_instance" "postgres" {
engine = "postgres"
engine_version = "16"
instance_class = "db.t3.micro"
allocated_storage = 20
db_name = "myapp"
username = "appuser"
password = var.db_password # From variable (never hardcode)