-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo-arch.html
More file actions
2860 lines (2693 loc) · 165 KB
/
Copy pathgo-arch.html
File metadata and controls
2860 lines (2693 loc) · 165 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>Go Software Architecture — Deep Guide</title>
<link rel="stylesheet" href="go-arch.css">
<link
href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500&display=swap"
rel="stylesheet">
</head>
<body>
<!-- ═══ HERO ═══ -->
<div class="hero">
<div class="hero-tag">Go Software Architecture — Complete Deep Guide</div>
<h1>10 Production-Grade <span>Go Architectures</span><br>Fully Mastered</h1>
<p>From a tiny blog to a billion-user fintech platform — every major software architecture pattern used in the Go
industry explained with code, diagrams, bottlenecks, real-world use cases, and decision frameworks.</p>
<div class="hero-pills">
<div class="hpill hp1">① Monolithic</div>
<div class="hpill hp2">② Microservices</div>
<div class="hpill hp3">③ Event-Driven</div>
<div class="hpill hp4">④ Clean Arch</div>
<div class="hpill hp5">⑤ Layered (N-Tier)</div>
<div class="hpill hp6">⑥ Hexagonal</div>
<div class="hpill hp7">⑦ CQRS</div>
<div class="hpill hp8">⑧ Serverless</div>
<div class="hpill hp9">⑨ SOA</div>
<div class="hpill hp10">⑩ DDD</div>
</div>
</div>
<!-- ═══ NAV ═══ -->
<nav>
<a href="#overview">Overview</a>
<a href="#monolithic">Monolithic</a>
<a href="#microservices">Microservices</a>
<a href="#event">Event-Driven</a>
<a href="#clean">Clean Arch</a>
<a href="#layered">Layered</a>
<a href="#hexagonal">Hexagonal</a>
<a href="#cqrs">CQRS</a>
<a href="#serverless">Serverless</a>
<a href="#soa">SOA</a>
<a href="#ddd">DDD</a>
<a href="#decision">Decision Guide</a>
<a href="#summary">Summary Table</a>
</nav>
<!-- ═══ OVERVIEW ═══ -->
<section id="overview">
<div class="container">
<div class="section-label">Section 01</div>
<div class="section-title">Architecture Categories & Landscape</div>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px;margin-bottom:28px;">
<div
style="background:var(--mono-dim);border:1px solid rgba(0,212,170,.2);border-radius:10px;padding:16px 18px;text-align:center;">
<div style="font-family:'Syne',sans-serif;font-size:16px;font-weight:800;color:var(--mono);">Structural
Patterns</div>
<div style="font-size:12px;color:var(--muted);margin-top:4px;">How the codebase is organized</div>
<div style="margin-top:10px;display:flex;gap:6px;flex-wrap:wrap;justify-content:center;">
<span class="tag t-mono">Monolithic</span><span class="tag t-layer">Layered</span><span
class="tag t-clean">Clean</span><span class="tag t-hexa">Hexagonal</span><span
class="tag t-ddd">DDD</span>
</div>
</div>
<div
style="background:var(--micro-dim);border:1px solid rgba(255,107,53,.2);border-radius:10px;padding:16px 18px;text-align:center;">
<div style="font-family:'Syne',sans-serif;font-size:16px;font-weight:800;color:var(--micro);">Deployment
Patterns</div>
<div style="font-size:12px;color:var(--muted);margin-top:4px;">How services are deployed & scaled</div>
<div style="margin-top:10px;display:flex;gap:6px;flex-wrap:wrap;justify-content:center;">
<span class="tag t-micro">Microservices</span><span class="tag t-soa">SOA</span><span
class="tag t-server">Serverless</span>
</div>
</div>
<div
style="background:var(--event-dim);border:1px solid rgba(124,106,247,.2);border-radius:10px;padding:16px 18px;text-align:center;">
<div style="font-family:'Syne',sans-serif;font-size:16px;font-weight:800;color:var(--event);">Communication
Patterns</div>
<div style="font-size:12px;color:var(--muted);margin-top:4px;">How components communicate & coordinate</div>
<div style="margin-top:10px;display:flex;gap:6px;flex-wrap:wrap;justify-content:center;">
<span class="tag t-event">Event-Driven</span><span class="tag t-cqrs">CQRS</span>
</div>
</div>
</div>
<div class="arch-overview-grid">
<div class="ao-card ac-mono"><span class="ao-icon">🏛️</span>
<div class="ao-name">Monolithic</div>
<div class="ao-cat">Structural</div>
<div class="ao-desc">Single deployable unit. All modules in one process.</div>
<div class="ao-num">01</div>
</div>
<div class="ao-card ac-micro"><span class="ao-icon">🔬</span>
<div class="ao-name">Microservices</div>
<div class="ao-cat">Deployment</div>
<div class="ao-desc">Independent services, each owning its domain & data.</div>
<div class="ao-num">02</div>
</div>
<div class="ao-card ac-event"><span class="ao-icon">⚡</span>
<div class="ao-name">Event-Driven</div>
<div class="ao-cat">Communication</div>
<div class="ao-desc">Async event streams decouple producers from consumers.</div>
<div class="ao-num">03</div>
</div>
<div class="ao-card ac-clean"><span class="ao-icon">🎯</span>
<div class="ao-name">Clean Arch</div>
<div class="ao-cat">Structural</div>
<div class="ao-desc">Dependency inversion: domain at center, infra at edge.</div>
<div class="ao-num">04</div>
</div>
<div class="ao-card ac-layer"><span class="ao-icon">🥞</span>
<div class="ao-name">Layered (N-Tier)</div>
<div class="ao-cat">Structural</div>
<div class="ao-desc">Strict horizontal layers: Presentation → Business → Data.</div>
<div class="ao-num">05</div>
</div>
<div class="ao-card ac-hexa"><span class="ao-icon">⬡</span>
<div class="ao-name">Hexagonal</div>
<div class="ao-cat">Structural</div>
<div class="ao-desc">Ports & Adapters. Application core with plug-in interfaces.</div>
<div class="ao-num">06</div>
</div>
<div class="ao-card ac-cqrs"><span class="ao-icon">⚖️</span>
<div class="ao-name">CQRS</div>
<div class="ao-cat">Communication</div>
<div class="ao-desc">Commands (write) and Queries (read) on separate models.</div>
<div class="ao-num">07</div>
</div>
<div class="ao-card ac-server"><span class="ao-icon">☁️</span>
<div class="ao-name">Serverless</div>
<div class="ao-cat">Deployment</div>
<div class="ao-desc">Functions-as-a-Service. No server management.</div>
<div class="ao-num">08</div>
</div>
<div class="ao-card ac-soa"><span class="ao-icon">🕸️</span>
<div class="ao-name">SOA</div>
<div class="ao-cat">Deployment</div>
<div class="ao-desc">Enterprise services over a shared ESB/message bus.</div>
<div class="ao-num">09</div>
</div>
<div class="ao-card ac-ddd"><span class="ao-icon">🌐</span>
<div class="ao-name">DDD</div>
<div class="ao-cat">Structural</div>
<div class="ao-desc">Domain model drives architecture. Bounded contexts.</div>
<div class="ao-num">10</div>
</div>
</div>
<!-- Scale-Complexity Grid -->
<div
style="background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:24px;margin-top:8px;">
<div
style="font-family:'Space Mono',monospace;font-size:10px;text-transform:uppercase;letter-spacing:2px;color:var(--muted);margin-bottom:16px;">
Architecture Selection by Project Scale & Complexity</div>
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:12px;text-align:center;">
<div
style="border:1px solid rgba(163,230,53,.2);border-radius:8px;padding:14px;background:rgba(163,230,53,.05);">
<div
style="font-family:'Syne',sans-serif;font-size:13px;font-weight:700;color:var(--cqrs);margin-bottom:8px;">
Small Project</div>
<div style="font-size:11px;color:var(--muted);margin-bottom:8px;">1-5 devs · MVP · Startup</div>
<div class="tag t-mono" style="display:inline-block;margin:2px;">Monolithic</div>
<div class="tag t-layer" style="display:inline-block;margin:2px;">Layered</div>
</div>
<div
style="border:1px solid rgba(247,201,72,.2);border-radius:8px;padding:14px;background:rgba(247,201,72,.05);">
<div
style="font-family:'Syne',sans-serif;font-size:13px;font-weight:700;color:var(--clean);margin-bottom:8px;">
Medium Project</div>
<div style="font-size:11px;color:var(--muted);margin-bottom:8px;">5-20 devs · Growing SaaS</div>
<div class="tag t-clean" style="display:inline-block;margin:2px;">Clean Arch</div>
<div class="tag t-hexa" style="display:inline-block;margin:2px;">Hexagonal</div>
<div class="tag t-ddd" style="display:inline-block;margin:2px;">DDD</div>
</div>
<div
style="border:1px solid rgba(255,107,53,.2);border-radius:8px;padding:14px;background:rgba(255,107,53,.05);">
<div
style="font-family:'Syne',sans-serif;font-size:13px;font-weight:700;color:var(--micro);margin-bottom:8px;">
Large Project</div>
<div style="font-size:11px;color:var(--muted);margin-bottom:8px;">20-100+ devs · Enterprise</div>
<div class="tag t-micro" style="display:inline-block;margin:2px;">Microservices</div>
<div class="tag t-event" style="display:inline-block;margin:2px;">Event-Driven</div>
<div class="tag t-cqrs" style="display:inline-block;margin:2px;">CQRS</div>
</div>
<div
style="border:1px solid rgba(52,211,153,.2);border-radius:8px;padding:14px;background:rgba(52,211,153,.05);">
<div
style="font-family:'Syne',sans-serif;font-size:13px;font-weight:700;color:var(--soa);margin-bottom:8px;">
Hyper-Scale</div>
<div style="font-size:11px;color:var(--muted);margin-bottom:8px;">100+ devs · Platform</div>
<div class="tag t-soa" style="display:inline-block;margin:2px;">SOA</div>
<div class="tag t-server" style="display:inline-block;margin:2px;">Serverless</div>
<div class="tag t-micro" style="display:inline-block;margin:2px;">Microservices</div>
</div>
</div>
</div>
</div>
</section>
<!-- ═══ MONOLITHIC ═══ -->
<section id="monolithic" class="ac-mono">
<div class="container">
<div class="section-label">Architecture 01 · Structural</div>
<div class="section-title" style="margin-bottom:0">Monolithic Architecture</div>
<div class="arch-block" style="margin-top:28px">
<div class="arch-header ac-mono">
<div class="arch-icon-lg">🏛️</div>
<div>
<div class="arch-name">Monolithic Architecture</div>
<div class="arch-cat">Structural · Single Deployable Unit · GoF Foundation</div>
<div class="arch-tagline">An application where <strong>all functionality is bundled into a single deployable
binary</strong>. All modules — HTTP handlers, business logic, database access, authentication — exist in
one Go binary, run in one process, and are deployed together. The default starting architecture for most
projects.</div>
<div class="stat-row">
<span class="stat">Deployment: Single binary</span>
<span class="stat">Process: One</span>
<span class="stat">DB: Typically one shared</span>
<span class="stat">Best team size: 1–15</span>
</div>
</div>
</div>
<!-- Characteristics -->
<div class="info-grid">
<div class="info-block">
<h4><span class="dot" style="background:var(--mono)"></span> What Is It?</h4>
<p>Everything lives in one codebase, one binary, one process. A Go monolith might have packages like
<code>/handlers</code>, <code>/services</code>, <code>/repository</code>, <code>/models</code> — all
compiled into a single <code>go build</code> output. No network calls between components; they call each
other as regular Go function calls.
</p>
<p>A well-structured monolith uses internal package boundaries to enforce modularity — the "modular
monolith" variant is the best starting point for most production Go systems.</p>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--mono)"></span> Characteristics</h4>
<ul>
<li><strong>Single process:</strong> all goroutines share the same memory</li>
<li><strong>In-process calls:</strong> function calls, not HTTP/gRPC — zero latency</li>
<li><strong>Shared database:</strong> one schema, one connection pool</li>
<li><strong>Unified deployment:</strong> one <code>go build</code>, one Docker image</li>
<li><strong>Vertical scaling:</strong> bigger machine → bigger monolith</li>
<li><strong>Simple debugging:</strong> one stack trace, one log stream</li>
</ul>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--mono)"></span> How It Works (Go)</h4>
<div class="steps" style="margin-top:8px">
<div class="step">
<div class="step-num" style="background:var(--mono-dim);color:var(--mono);">01</div>
<div class="step-body">
<h5>HTTP Request enters</h5>
<p>Gin/Echo/Chi router in <code>main.go</code> receives the request.</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--mono-dim);color:var(--mono);">02</div>
<div class="step-body">
<h5>Handler layer</h5>
<p><code>/handlers/order.go</code> parses, validates request, calls service.</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--mono-dim);color:var(--mono);">03</div>
<div class="step-body">
<h5>Service / Business layer</h5>
<p><code>/services/order.go</code> applies business rules — direct function call, zero overhead.</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--mono-dim);color:var(--mono);">04</div>
<div class="step-body">
<h5>Repository / Data layer</h5>
<p><code>/repository/order.go</code> queries PostgreSQL. Returns to handler. HTTP response.</p>
</div>
</div>
</div>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--mono)"></span> Complexity & Scale Metrics</h4>
<div class="meter-row"><span class="meter-label">Setup complexity</span>
<div class="meter-track">
<div class="meter-fill" style="width:15%;background:var(--mono)"></div>
</div><span class="meter-val">Very Low</span>
</div>
<div class="meter-row"><span class="meter-label">Dev velocity</span>
<div class="meter-track">
<div class="meter-fill" style="width:90%;background:var(--pro)"></div>
</div><span class="meter-val">Very High</span>
</div>
<div class="meter-row"><span class="meter-label">Operational cost</span>
<div class="meter-track">
<div class="meter-fill" style="width:10%;background:var(--mono)"></div>
</div><span class="meter-val">Very Low</span>
</div>
<div class="meter-row"><span class="meter-label">Horizontal scale</span>
<div class="meter-track">
<div class="meter-fill" style="width:30%;background:var(--con)"></div>
</div><span class="meter-val">Limited</span>
</div>
<div class="meter-row"><span class="meter-label">Team scalability</span>
<div class="meter-track">
<div class="meter-fill" style="width:25%;background:var(--con)"></div>
</div><span class="meter-val">Limited</span>
</div>
<div class="meter-row"><span class="meter-label">Debugging ease</span>
<div class="meter-track">
<div class="meter-fill" style="width:95%;background:var(--pro)"></div>
</div><span class="meter-val">Excellent</span>
</div>
</div>
</div>
<!-- Suitability -->
<div class="info-block" style="margin-bottom:14px">
<h4><span class="dot" style="background:var(--mono)"></span> Project Suitability</h4>
<div class="suit-grid">
<span class="suit-badge sb-best">✓ Startup MVP</span>
<span class="suit-badge sb-best">✓ Small SaaS</span>
<span class="suit-badge sb-best">✓ Internal Tools</span>
<span class="suit-badge sb-best">✓ Blog / CMS</span>
<span class="suit-badge sb-best">✓ Small E-commerce</span>
<span class="suit-badge sb-good">~ Medium REST API</span>
<span class="suit-badge sb-good">~ ERP (early stage)</span>
<span class="suit-badge sb-avoid">✗ Multi-team Platform</span>
<span class="suit-badge sb-avoid">✗ High-scale Real-time</span>
<span class="suit-badge sb-avoid">✗ Independent deploy cycles</span>
<span class="suit-badge sb-size-sm">Small ✓</span>
<span class="suit-badge sb-size-md">Medium ✓</span>
<span class="suit-badge sb-size-lg">Large ✗</span>
</div>
</div>
<!-- Diagram -->
<div class="diagram-wrap">
<svg viewBox="0 0 700 220" xmlns="http://www.w3.org/2000/svg" style="font-family:'Space Mono',monospace">
<defs>
<marker id="am" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
<polygon points="0 0,7 2.5,0 5" fill="#00d4aa" />
</marker>
</defs>
<!-- Client -->
<rect x="10" y="80" width="80" height="60" rx="8" fill="rgba(0,212,170,.08)" stroke="rgba(0,212,170,.3)"
stroke-width="1.5" />
<text x="50" y="107" text-anchor="middle" fill="#00d4aa" font-size="11" font-weight="bold">Client</text>
<text x="50" y="122" text-anchor="middle" fill="#8892a4" font-size="9">Browser/App</text>
<line x1="90" y1="110" x2="130" y2="110" stroke="#00d4aa" stroke-width="1.5" marker-end="url(#am)" />
<!-- Monolith big box -->
<rect x="130" y="20" width="440" height="180" rx="12" fill="rgba(0,212,170,.06)" stroke="#00d4aa"
stroke-width="2" stroke-dasharray="6,3" />
<text x="350" y="42" text-anchor="middle" fill="#00d4aa" font-size="10" font-weight="bold"
letter-spacing="2">SINGLE GO BINARY — ONE PROCESS</text>
<!-- Layers inside -->
<rect x="150" y="52" width="100" height="40" rx="6" fill="rgba(0,212,170,.15)" stroke="#00d4aa"
stroke-width="1.5" />
<text x="200" y="68" text-anchor="middle" fill="#00d4aa" font-size="10" font-weight="bold">Handlers</text>
<text x="200" y="82" text-anchor="middle" fill="#8892a4" font-size="8">Gin/Echo/Chi</text>
<rect x="270" y="52" width="100" height="40" rx="6" fill="rgba(0,212,170,.15)" stroke="#00d4aa"
stroke-width="1.5" />
<text x="320" y="68" text-anchor="middle" fill="#00d4aa" font-size="10" font-weight="bold">Services</text>
<text x="320" y="82" text-anchor="middle" fill="#8892a4" font-size="8">Business Logic</text>
<rect x="390" y="52" width="100" height="40" rx="6" fill="rgba(0,212,170,.15)" stroke="#00d4aa"
stroke-width="1.5" />
<text x="440" y="68" text-anchor="middle" fill="#00d4aa" font-size="10" font-weight="bold">Repository</text>
<text x="440" y="82" text-anchor="middle" fill="#8892a4" font-size="8">Data Access</text>
<!-- Function call arrows (inside same process) -->
<line x1="250" y1="72" x2="270" y2="72" stroke="#00d4aa" stroke-width="1.5" marker-end="url(#am)" />
<line x1="370" y1="72" x2="390" y2="72" stroke="#00d4aa" stroke-width="1.5" marker-end="url(#am)" />
<text x="260" y="65" text-anchor="middle" fill="#6272a4" font-size="8">func()</text>
<text x="380" y="65" text-anchor="middle" fill="#6272a4" font-size="8">func()</text>
<!-- Sub-modules row -->
<rect x="150" y="110" width="90" height="32" rx="5" fill="rgba(0,212,170,.08)" stroke="rgba(0,212,170,.25)"
stroke-width="1" />
<text x="195" y="126" text-anchor="middle" fill="#8892a4" font-size="9">Auth Module</text>
<rect x="250" y="110" width="90" height="32" rx="5" fill="rgba(0,212,170,.08)" stroke="rgba(0,212,170,.25)"
stroke-width="1" />
<text x="295" y="126" text-anchor="middle" fill="#8892a4" font-size="9">Order Module</text>
<rect x="350" y="110" width="90" height="32" rx="5" fill="rgba(0,212,170,.08)" stroke="rgba(0,212,170,.25)"
stroke-width="1" />
<text x="395" y="126" text-anchor="middle" fill="#8892a4" font-size="9">Menu Module</text>
<rect x="450" y="110" width="100" height="32" rx="5" fill="rgba(0,212,170,.08)" stroke="rgba(0,212,170,.25)"
stroke-width="1" />
<text x="500" y="126" text-anchor="middle" fill="#8892a4" font-size="9">Payment Module</text>
<!-- Shared Memory label -->
<rect x="150" y="155" width="400" height="28" rx="5" fill="rgba(0,212,170,.05)" stroke="rgba(0,212,170,.15)"
stroke-width="1" />
<text x="350" y="173" text-anchor="middle" fill="#6272a4" font-size="9">Shared Memory — Shared Types —
In-Process Communication (zero network latency)</text>
<!-- DB -->
<rect x="590" y="80" width="100" height="60" rx="8" fill="rgba(74,222,128,.08)" stroke="rgba(74,222,128,.3)"
stroke-width="1.5" />
<text x="640" y="105" text-anchor="middle" fill="#4ade80" font-size="11"
font-weight="bold">PostgreSQL</text>
<text x="640" y="120" text-anchor="middle" fill="#8892a4" font-size="9">Shared DB</text>
<line x1="570" y1="110" x2="590" y2="110" stroke="#4ade80" stroke-width="1.5" marker-end="url(#am)" />
</svg>
</div>
<!-- Code -->
<div class="code-bar">
<div class="dr"></div>
<div class="dy"></div>
<div class="dg"></div><span class="cb-label">monolith/main.go — Modular Monolith Structure</span>
</div>
<div class="code-block"><span class="cmt">// Recommended Go Modular Monolith project structure:</span>
<span class="cmt">// myapp/</span>
<span class="cmt">// ├── cmd/server/main.go ← Entry point — wires everything</span>
<span class="cmt">// ├── internal/</span>
<span class="cmt">// │ ├── handlers/ ← HTTP layer (Gin/Echo)</span>
<span class="cmt">// │ │ ├── order.go</span>
<span class="cmt">// │ │ └── menu.go</span>
<span class="cmt">// │ ├── services/ ← Business logic (pure Go, no HTTP deps)</span>
<span class="cmt">// │ │ ├── order.go</span>
<span class="cmt">// │ │ └── menu.go</span>
<span class="cmt">// │ ├── repository/ ← Data access (SQL, Redis)</span>
<span class="cmt">// │ │ ├── postgres/</span>
<span class="cmt">// │ │ └── redis/</span>
<span class="cmt">// │ ├── domain/ ← Types, interfaces, business entities</span>
<span class="cmt">// │ └── config/ ← App config loading</span>
<span class="cmt">// └── pkg/ ← Shared utilities (logging, errors)</span>
<span class="kw">package</span> main
<span class="kw">import</span> (
<span class="str">"github.com/gin-gonic/gin"</span>
<span class="str">"myapp/internal/handlers"</span>
<span class="str">"myapp/internal/repository/postgres"</span>
<span class="str">"myapp/internal/services"</span>
)
<span class="kw">func</span> <span class="fn">main</span>() {
<span class="cmt">// Manual Dependency Injection — wired at startup</span>
db := postgres.<span class="fn">New</span>(cfg.DatabaseURL)
repo := postgres.<span class="fn">NewOrderRepo</span>(db)
svc := services.<span class="fn">NewOrderService</span>(repo)
hdlr := handlers.<span class="fn">NewOrderHandler</span>(svc)
r := gin.<span class="fn">Default</span>()
r.<span class="fn">POST</span>(<span class="str">"/orders"</span>, hdlr.<span class="fn">Create</span>)
r.<span class="fn">GET</span>(<span class="str">"/orders/:id"</span>, hdlr.<span class="fn">Get</span>)
r.<span class="fn">Run</span>(<span class="str">":8080"</span>)
<span class="cmt">// No service discovery. No network calls between modules.</span>
<span class="cmt">// Everything: one process, one binary, one deploy.</span>
}
</div>
<div class="bottleneck">
<h4>⚠ BOTTLENECKS & KNOWN ISSUES</h4>
<ul>
<li><strong>Scaling bottleneck:</strong> Must scale the entire app even if only one module is under load
</li>
<li><strong>Deployment bottleneck:</strong> One bug in any module can take down the entire system</li>
<li><strong>Team bottleneck:</strong> Merge conflicts increase as team size grows past ~15 developers</li>
<li><strong>Technology bottleneck:</strong> Entire app must use same Go version, same dependencies</li>
<li><strong>Memory:</strong> Single process means one large heap — high-frequency GC pauses at scale</li>
</ul>
</div>
<div class="pro-con-grid">
<div class="pro-list">
<h4>✓ ADVANTAGES</h4>
<ul>
<li>Simplest possible architecture — YAGNI-compliant</li>
<li>Zero network latency between modules (in-process calls)</li>
<li>One log stream, one debugger, one deployment unit</li>
<li>Trivial local development — one <code>go run</code> command</li>
<li>ACID transactions across entire system trivially</li>
<li>No service discovery, no distributed tracing overhead</li>
<li>Best for early-stage products where speed matters most</li>
<li>Easy to refactor — compiler catches all breakage</li>
</ul>
</div>
<div class="con-list">
<h4>✗ DISADVANTAGES</h4>
<ul>
<li>One module failure can crash entire application</li>
<li>Cannot scale individual modules independently</li>
<li>Merge conflicts and coordination overhead at large team sizes</li>
<li>Tech stack locked — no module-level polyglot</li>
<li>Long build/test times as codebase grows</li>
<li>Deploy all-or-nothing — risky for large releases</li>
<li>Tight coupling risk: modules can call each other freely</li>
</ul>
</div>
</div>
<div class="example-card">
<div class="example-icon">🍕</div>
<div>
<div class="example-title" style="color:var(--mono)">Domino's-style Restaurant Ordering Platform (Early
Stage)</div>
<div class="example-desc">A single Go binary handles: online menu browsing, cart management, order
placement, payment processing (Stripe), kitchen notification, driver dispatch, and admin dashboard. All
modules share a PostgreSQL connection pool and Redis cache. One deploy, one server, one codebase. Team of
5 ships features daily without coordination overhead. When order volumes hit 10K/day, deploy on a bigger
VM — no architectural change needed until that VM is maxed out.</div>
<div class="tags">
<span class="tag t-mono">Online Ordering</span>
<span class="tag t-mono">Menu Management</span>
<span class="tag t-mono">Payment (Stripe)</span>
<span class="tag t-mono">Kitchen Dashboard</span>
<span class="tag green">Single Deploy</span>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- ═══ MICROSERVICES ═══ -->
<section id="microservices" class="ac-micro">
<div class="container">
<div class="section-label">Architecture 02 · Deployment</div>
<div class="section-title" style="margin-bottom:0">Microservices Architecture</div>
<div class="arch-block" style="margin-top:28px">
<div class="arch-header ac-micro">
<div class="arch-icon-lg">🔬</div>
<div>
<div class="arch-name">Microservices Architecture</div>
<div class="arch-cat">Deployment Pattern · Independent Services · Cloud-Native</div>
<div class="arch-tagline">An application structured as a collection of <strong>small, autonomous
services</strong> — each owning its own data, deployed independently, communicating over the network
(HTTP/gRPC/message queues). Each service is a separate Go binary. The gold standard for large-scale,
multi-team systems.</div>
<div class="stat-row">
<span class="stat">Deployment: Independent binaries</span>
<span class="stat">Communication: gRPC / HTTP / Events</span>
<span class="stat">DB: One DB per service</span>
<span class="stat">Best team: 2-pizza rule per service</span>
</div>
</div>
</div>
<div class="info-grid">
<div class="info-block">
<h4><span class="dot" style="background:var(--micro)"></span> What Is It?</h4>
<p>Instead of one big Go binary, you have 10-50+ small Go binaries: <code>order-service</code>,
<code>menu-service</code>, <code>payment-service</code>, <code>notification-service</code>, each in its
own repo. They communicate via gRPC (internal) or REST (external). Each owns its own PostgreSQL
schema/database. Each can be deployed, scaled, and failed independently.
</p>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--micro)"></span> Core Principles</h4>
<ul>
<li><strong>Single Responsibility:</strong> each service does ONE thing well</li>
<li><strong>Data isolation:</strong> no shared databases — each service owns its data</li>
<li><strong>Deploy independence:</strong> update order-service without touching menu-service</li>
<li><strong>Failure isolation:</strong> payment-service failure doesn't crash menu browsing</li>
<li><strong>Technology freedom:</strong> one service can be Go, another Python (rarely needed)</li>
<li><strong>Owned by one team:</strong> Amazon "two-pizza" rule</li>
</ul>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--micro)"></span> Key Requirements</h4>
<ul>
<li><strong>Service Discovery:</strong> Consul, etcd, or Kubernetes DNS</li>
<li><strong>API Gateway:</strong> Kong, Traefik, or custom Go gateway</li>
<li><strong>Distributed Tracing:</strong> OpenTelemetry + Jaeger / Zipkin</li>
<li><strong>Centralized Logging:</strong> ELK / Loki / Datadog</li>
<li><strong>Circuit Breakers:</strong> Sony gobreaker / Hystrix-go</li>
<li><strong>Health checks + readiness probes</strong> on every service</li>
<li><strong>Container orchestration:</strong> Kubernetes (standard)</li>
</ul>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--micro)"></span> Complexity Metrics</h4>
<div class="meter-row"><span class="meter-label">Setup complexity</span>
<div class="meter-track">
<div class="meter-fill" style="width:90%;background:var(--micro)"></div>
</div><span class="meter-val">Very High</span>
</div>
<div class="meter-row"><span class="meter-label">Dev velocity</span>
<div class="meter-track">
<div class="meter-fill" style="width:50%;background:var(--clean)"></div>
</div><span class="meter-val">Medium</span>
</div>
<div class="meter-row"><span class="meter-label">Operational cost</span>
<div class="meter-track">
<div class="meter-fill" style="width:88%;background:var(--micro)"></div>
</div><span class="meter-val">Very High</span>
</div>
<div class="meter-row"><span class="meter-label">Horizontal scale</span>
<div class="meter-track">
<div class="meter-fill" style="width:98%;background:var(--pro)"></div>
</div><span class="meter-val">Excellent</span>
</div>
<div class="meter-row"><span class="meter-label">Team scalability</span>
<div class="meter-track">
<div class="meter-fill" style="width:95%;background:var(--pro)"></div>
</div><span class="meter-val">Excellent</span>
</div>
<div class="meter-row"><span class="meter-label">Debugging ease</span>
<div class="meter-track">
<div class="meter-fill" style="width:20%;background:var(--con)"></div>
</div><span class="meter-val">Hard</span>
</div>
</div>
</div>
<div class="info-block" style="margin-bottom:14px">
<h4><span class="dot" style="background:var(--micro)"></span> Project Suitability</h4>
<div class="suit-grid">
<span class="suit-badge sb-best">✓ Large E-Commerce (Amazon)</span>
<span class="suit-badge sb-best">✓ Fintech Platform</span>
<span class="suit-badge sb-best">✓ Multi-team SaaS</span>
<span class="suit-badge sb-best">✓ High-scale API Platform</span>
<span class="suit-badge sb-best">✓ Netflix/Uber-style apps</span>
<span class="suit-badge sb-good">~ Growing startup with product-market fit</span>
<span class="suit-badge sb-avoid">✗ Solo developer / Small team</span>
<span class="suit-badge sb-avoid">✗ MVP / Prototype</span>
<span class="suit-badge sb-avoid">✗ Simple CRUD app</span>
<span class="suit-badge sb-size-lg">Large ✓</span>
<span class="suit-badge sb-size-xl"
style="background:rgba(248,113,113,.1);color:var(--con);border-color:rgba(248,113,113,.2);">Enterprise
✓</span>
</div>
</div>
<!-- Architecture Diagram -->
<div class="diagram-wrap">
<svg viewBox="0 0 700 300" xmlns="http://www.w3.org/2000/svg" style="font-family:'Space Mono',monospace">
<defs>
<marker id="amicro" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
<polygon points="0 0,7 2.5,0 5" fill="#ff6b35" />
</marker>
<marker id="agrpc" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
<polygon points="0 0,7 2.5,0 5" fill="#7c6af7" />
</marker>
</defs>
<!-- Client -->
<rect x="10" y="130" width="70" height="40" rx="7" fill="rgba(255,107,53,.08)" stroke="rgba(255,107,53,.35)"
stroke-width="1.5" />
<text x="45" y="147" text-anchor="middle" fill="#ff6b35" font-size="10" font-weight="bold">Client</text>
<text x="45" y="160" text-anchor="middle" fill="#8892a4" font-size="8">App/Web</text>
<line x1="80" y1="150" x2="110" y2="150" stroke="#ff6b35" stroke-width="1.5" marker-end="url(#amicro)" />
<!-- API Gateway -->
<rect x="110" y="115" width="110" height="70" rx="8" fill="rgba(255,107,53,.2)" stroke="#ff6b35"
stroke-width="2.5" />
<text x="165" y="143" text-anchor="middle" fill="#ff6b35" font-size="11" font-weight="bold">API
Gateway</text>
<text x="165" y="158" text-anchor="middle" fill="#8892a4" font-size="9">Rate Limit</text>
<text x="165" y="170" text-anchor="middle" fill="#8892a4" font-size="9">Auth · Routing</text>
<!-- Services column -->
<line x1="220" y1="135" x2="255" y2="80" stroke="#ff6b35" stroke-width="1.3" marker-end="url(#amicro)" />
<line x1="220" y1="148" x2="255" y2="148" stroke="#ff6b35" stroke-width="1.3" marker-end="url(#amicro)" />
<line x1="220" y1="162" x2="255" y2="220" stroke="#ff6b35" stroke-width="1.3" marker-end="url(#amicro)" />
<!-- Order Service -->
<rect x="255" y="55" width="110" height="50" rx="7" fill="rgba(255,107,53,.12)" stroke="rgba(255,107,53,.4)"
stroke-width="1.5" />
<text x="310" y="76" text-anchor="middle" fill="#ff6b35" font-size="10" font-weight="bold">Order
Service</text>
<text x="310" y="89" text-anchor="middle" fill="#8892a4" font-size="8">:8081 · own DB</text>
<!-- Own DB -->
<rect x="370" y="60" width="60" height="40" rx="5" fill="rgba(74,222,128,.08)" stroke="rgba(74,222,128,.3)"
stroke-width="1" />
<text x="400" y="78" text-anchor="middle" fill="#4ade80" font-size="8">Orders DB</text>
<text x="400" y="90" text-anchor="middle" fill="#6272a4" font-size="7">Postgres</text>
<line x1="365" y1="80" x2="370" y2="80" stroke="#4ade80" stroke-width="1" />
<!-- Menu Service -->
<rect x="255" y="123" width="110" height="50" rx="7" fill="rgba(255,107,53,.18)" stroke="#ff6b35"
stroke-width="2" />
<text x="310" y="144" text-anchor="middle" fill="#ff6b35" font-size="10" font-weight="bold">Menu
Service</text>
<text x="310" y="157" text-anchor="middle" fill="#8892a4" font-size="8">:8082 · own DB</text>
<rect x="370" y="128" width="60" height="40" rx="5" fill="rgba(74,222,128,.08)" stroke="rgba(74,222,128,.3)"
stroke-width="1" />
<text x="400" y="146" text-anchor="middle" fill="#4ade80" font-size="8">Menu DB</text>
<text x="400" y="158" text-anchor="middle" fill="#6272a4" font-size="7">Postgres</text>
<line x1="365" y1="148" x2="370" y2="148" stroke="#4ade80" stroke-width="1" />
<!-- Payment Service -->
<rect x="255" y="197" width="110" height="50" rx="7" fill="rgba(255,107,53,.12)"
stroke="rgba(255,107,53,.4)" stroke-width="1.5" />
<text x="310" y="218" text-anchor="middle" fill="#ff6b35" font-size="10" font-weight="bold">Payment
Svc</text>
<text x="310" y="231" text-anchor="middle" fill="#8892a4" font-size="8">:8083 · own DB</text>
<rect x="370" y="202" width="60" height="40" rx="5" fill="rgba(74,222,128,.08)" stroke="rgba(74,222,128,.3)"
stroke-width="1" />
<text x="400" y="220" text-anchor="middle" fill="#4ade80" font-size="8">Payment DB</text>
<text x="400" y="232" text-anchor="middle" fill="#6272a4" font-size="7">Postgres</text>
<line x1="365" y1="222" x2="370" y2="222" stroke="#4ade80" stroke-width="1" />
<!-- gRPC between services -->
<line x1="365" y1="88" x2="440" y2="130" stroke="#7c6af7" stroke-width="1.2" stroke-dasharray="4,2"
marker-end="url(#agrpc)" />
<line x1="365" y1="160" x2="440" y2="210" stroke="#7c6af7" stroke-width="1.2" stroke-dasharray="4,2"
marker-end="url(#agrpc)" />
<text x="420" y="112" fill="#7c6af7" font-size="8">gRPC</text>
<text x="425" y="192" fill="#7c6af7" font-size="8">gRPC</text>
<!-- Notification Service -->
<rect x="440" y="110" width="110" height="50" rx="7" fill="rgba(255,107,53,.12)"
stroke="rgba(255,107,53,.4)" stroke-width="1.5" />
<text x="495" y="131" text-anchor="middle" fill="#ff6b35" font-size="10"
font-weight="bold">Notification</text>
<text x="495" y="144" text-anchor="middle" fill="#8892a4" font-size="8">:8084 · email/SMS</text>
<!-- Driver Service -->
<rect x="440" y="195" width="110" height="50" rx="7" fill="rgba(255,107,53,.12)"
stroke="rgba(255,107,53,.4)" stroke-width="1.5" />
<text x="495" y="216" text-anchor="middle" fill="#ff6b35" font-size="10" font-weight="bold">Driver
Service</text>
<text x="495" y="229" text-anchor="middle" fill="#8892a4" font-size="8">:8085 · GPS</text>
<!-- Message Broker -->
<rect x="570" y="130" width="120" height="50" rx="7" fill="rgba(124,106,247,.12)"
stroke="rgba(124,106,247,.4)" stroke-width="1.5" />
<text x="630" y="151" text-anchor="middle" fill="#7c6af7" font-size="10" font-weight="bold">Kafka /
NATS</text>
<text x="630" y="164" text-anchor="middle" fill="#8892a4" font-size="8">Event Bus</text>
<line x1="550" y1="135" x2="570" y2="148" stroke="#7c6af7" stroke-width="1" stroke-dasharray="3,2" />
<line x1="550" y1="215" x2="570" y2="162" stroke="#7c6af7" stroke-width="1" stroke-dasharray="3,2" />
<!-- K8s label -->
<rect x="10" y="265" width="680" height="20" rx="4" fill="rgba(255,107,53,.04)"
stroke="rgba(255,107,53,.15)" stroke-width="1" />
<text x="350" y="279" text-anchor="middle" fill="#6272a4" font-size="9">Kubernetes — Service Discovery —
Distributed Tracing (OpenTelemetry) — Centralized Logging</text>
</svg>
</div>
<div class="code-bar">
<div class="dr"></div>
<div class="dy"></div>
<div class="dg"></div><span class="cb-label">microservices/order-service/main.go — gRPC Server</span>
</div>
<div class="code-block"><span class="cmt">// Each microservice is a standalone Go binary</span>
<span class="cmt">// order-service/</span>
<span class="cmt">// ├── cmd/main.go ← gRPC + HTTP server startup</span>
<span class="cmt">// ├── internal/</span>
<span class="cmt">// │ ├── handler/ ← gRPC handlers</span>
<span class="cmt">// │ ├── service/ ← Business logic</span>
<span class="cmt">// │ └── repository/ ← This service's OWN database</span>
<span class="cmt">// ├── proto/ ← Protobuf definitions</span>
<span class="cmt">// └── go.mod ← INDEPENDENT module — own dependencies!</span>
<span class="kw">package</span> main
<span class="kw">import</span> (
<span class="str">"google.golang.org/grpc"</span>
<span class="str">"go.opentelemetry.io/otel"</span> <span class="cmt">// Distributed tracing</span>
orderpb <span class="str">"order-service/proto/order"</span>
)
<span class="kw">func</span> <span class="fn">main</span>() {
<span class="cmt">// Each service: its own config, its own DB, its own port</span>
db := <span class="fn">connectOwnDatabase</span>(cfg.DatabaseURL)
svc := service.<span class="fn">New</span>(db)
<span class="cmt">// gRPC server with interceptors (tracing, logging, recovery)</span>
grpcServer := grpc.<span class="fn">NewServer</span>(
grpc.<span class="fn">UnaryInterceptor</span>(<span class="fn">otelgrpc.UnaryServerInterceptor</span>()),
grpc.<span class="fn">UnaryInterceptor</span>(<span class="fn">loggingInterceptor</span>),
)
orderpb.<span class="fn">RegisterOrderServiceServer</span>(grpcServer, svc)
<span class="cmt">// Health check for Kubernetes probes</span>
<span class="kw">go</span> <span class="fn">serveHealthCheck</span>(<span class="str">":8090"</span>)
grpcServer.<span class="fn">Serve</span>(lis)
<span class="cmt">// To call another service (e.g. payment-service):</span>
<span class="cmt">// conn, _ := grpc.Dial("payment-service:9090", grpc.WithInsecure())</span>
<span class="cmt">// paymentClient := paymentpb.NewPaymentServiceClient(conn)</span>
}
</div>
<div class="bottleneck">
<h4>⚠ BOTTLENECKS & DISTRIBUTED SYSTEM CHALLENGES</h4>
<ul>
<li><strong>Network latency:</strong> What was a function call is now an RPC — adds 1-10ms per hop</li>
<li><strong>Distributed transactions:</strong> No ACID across services — must use Saga Pattern or 2PC</li>
<li><strong>Service mesh complexity:</strong> Istio/Linkerd adds operational overhead</li>
<li><strong>Data consistency:</strong> Eventual consistency is the norm — harder to reason about</li>
<li><strong>Debugging:</strong> A single request spans 5+ services — requires distributed tracing</li>
<li><strong>Test environment:</strong> Running full system locally requires Docker Compose or Minikube</li>
</ul>
</div>
<div class="pro-con-grid">
<div class="pro-list">
<h4>✓ ADVANTAGES</h4>
<ul>
<li>Independent scaling per service (scale only what's under load)</li>
<li>Independent deployments — one team doesn't block another</li>
<li>Fault isolation — one service failure doesn't cascade</li>
<li>Teams own their service end-to-end (full autonomy)</li>
<li>Technology choice per service (rarely needed, but possible)</li>
<li>Smaller codebases per service — easier to understand</li>
<li>Industry standard for large cloud-native platforms</li>
</ul>
</div>
<div class="con-list">
<h4>✗ DISADVANTAGES</h4>
<ul>
<li>Massive operational complexity (K8s, service mesh, observability)</li>
<li>Distributed system fallacies — network is NOT reliable</li>
<li>Inter-service testing and integration test complexity</li>
<li>Data consistency and distributed transactions are hard</li>
<li>Latency overhead from network calls</li>
<li>Significant infrastructure cost vs monolith</li>
<li>Requires mature DevOps/platform engineering team</li>
</ul>
</div>
</div>
<div class="example-card">
<div class="example-icon">🚀</div>
<div>
<div class="example-title" style="color:var(--micro)">Uber Eats / Large Food Platform (Scale)</div>
<div class="example-desc">At Uber-scale: <strong>restaurant-service</strong> (menu, hours, onboarding) →
<strong>search-service</strong> (Elasticsearch, geo-search) → <strong>order-service</strong> (placement,
lifecycle) → <strong>pricing-service</strong> (surge, discounts) → <strong>payment-service</strong>
(Stripe, wallets) → <strong>dispatch-service</strong> (driver matching, routing) →
<strong>notification-service</strong> (push, SMS, email) → <strong>analytics-service</strong> (Kafka
consumer, data warehouse). Each team deploys 10x/day independently. Each service scales to handle its own
peak load.
</div>
<div class="tags">
<span class="tag t-micro">Independent Deploy</span>
<span class="tag t-micro">Per-Service Scaling</span>
<span class="tag t-micro">gRPC Internal</span>
<span class="tag t-micro">Kubernetes</span>
<span class="tag green">Fault Isolation</span>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- ═══ EVENT-DRIVEN ═══ -->
<section id="event" class="ac-event">
<div class="container">
<div class="section-label">Architecture 03 · Communication</div>
<div class="section-title" style="margin-bottom:0">Event-Driven Architecture</div>
<div class="arch-block" style="margin-top:28px">
<div class="arch-header ac-event">
<div class="arch-icon-lg">⚡</div>
<div>
<div class="arch-name">Event-Driven Architecture (EDA)</div>
<div class="arch-cat">Communication Pattern · Asynchronous · Reactive</div>
<div class="arch-tagline">Components communicate by <strong>producing and consuming events</strong>
asynchronously via a message broker (Kafka, NATS, RabbitMQ). Producers don't know who consumes their
events. Consumers don't know who produced. Maximum decoupling — perfect for systems where actions trigger
cascading reactions across many services.</div>
<div class="stat-row">
<span class="stat">Communication: Async events</span>
<span class="stat">Broker: Kafka / NATS / RabbitMQ</span>
<span class="stat">Coupling: Very Low</span>
<span class="stat">Consistency: Eventual</span>
</div>
</div>
</div>
<div class="info-grid">
<div class="info-block">
<h4><span class="dot" style="background:var(--event)"></span> Core Concepts</h4>
<ul>
<li><strong>Event:</strong> Immutable fact — "OrderPlaced", "PaymentFailed", "UserSignedUp"</li>
<li><strong>Producer:</strong> Service that emits events (doesn't know consumers)</li>
<li><strong>Consumer:</strong> Service that subscribes to topics (doesn't know producer)</li>
<li><strong>Topic/Channel:</strong> Named stream — "orders.placed", "payments.completed"</li>
<li><strong>Event Store:</strong> Append-only log (Kafka topic = ordered, replayed)</li>
<li><strong>Dead Letter Queue:</strong> Failed events routed for retry/inspection</li>
</ul>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--event)"></span> How It Works</h4>
<div class="steps" style="margin-top:8px">
<div class="step">
<div class="step-num" style="background:var(--event-dim);color:var(--event);">01</div>
<div class="step-body">
<h5>Action triggers event</h5>
<p>Order service places order → publishes <code>OrderPlaced</code> event to Kafka topic
<code>orders.placed</code>.
</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--event-dim);color:var(--event);">02</div>
<div class="step-body">
<h5>Broker persists event</h5>
<p>Kafka durably stores the event in ordered partition. Consumers can replay from any offset.</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--event-dim);color:var(--event);">03</div>
<div class="step-body">
<h5>Consumers react independently</h5>
<p>Kitchen, inventory, analytics, notification services each consume in parallel — at their own pace.
</p>
</div>
</div>
<div class="step">
<div class="step-num" style="background:var(--event-dim);color:var(--event);">04</div>
<div class="step-body">
<h5>Each consumer may produce</h5>
<p>Kitchen service consumes <code>OrderPlaced</code>, produces <code>CookingStarted</code>.
Notification consumes that, pushes to customer.</p>
</div>
</div>
</div>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--event)"></span> EDA Styles in Go</h4>
<ul>
<li><strong>Simple Pub/Sub:</strong> NATS JetStream — fastest, zero persistence, ideal for real-time</li>
<li><strong>Event Streaming:</strong> Kafka — durable, ordered, replayable — fintech/audit logs</li>
<li><strong>Message Queuing:</strong> RabbitMQ — work queues, routing, dead-letter</li>
<li><strong>In-process channels:</strong> Go channels for single-service event bus</li>
<li><strong>Event Sourcing:</strong> Events ARE the source of truth — replay to rebuild state</li>
</ul>
</div>
<div class="info-block">
<h4><span class="dot" style="background:var(--event)"></span> Complexity Metrics</h4>
<div class="meter-row"><span class="meter-label">Setup complexity</span>
<div class="meter-track">
<div class="meter-fill" style="width:72%;background:var(--event)"></div>
</div><span class="meter-val">High</span>
</div>
<div class="meter-row"><span class="meter-label">Coupling level</span>
<div class="meter-track">
<div class="meter-fill" style="width:5%;background:var(--pro)"></div>
</div><span class="meter-val">Very Low</span>
</div>
<div class="meter-row"><span class="meter-label">Throughput</span>
<div class="meter-track">
<div class="meter-fill" style="width:95%;background:var(--pro)"></div>
</div><span class="meter-val">Excellent</span>
</div>
<div class="meter-row"><span class="meter-label">Consistency</span>
<div class="meter-track">
<div class="meter-fill" style="width:30%;background:var(--con)"></div>
</div><span class="meter-val">Eventual</span>
</div>
<div class="meter-row"><span class="meter-label">Debugging</span>
<div class="meter-track">
<div class="meter-fill" style="width:22%;background:var(--con)"></div>
</div><span class="meter-val">Hard</span>
</div>
<div class="meter-row"><span class="meter-label">Resilience</span>
<div class="meter-track">
<div class="meter-fill" style="width:92%;background:var(--pro)"></div>
</div><span class="meter-val">Very High</span>
</div>
</div>
</div>
<div class="diagram-wrap">
<svg viewBox="0 0 700 200" xmlns="http://www.w3.org/2000/svg" style="font-family:'Space Mono',monospace">
<defs>
<marker id="aev" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
<polygon points="0 0,7 2.5,0 5" fill="#7c6af7" />
</marker>
</defs>
<!-- Producers -->
<rect x="10" y="30" width="110" height="40" rx="7" fill="rgba(124,106,247,.1)" stroke="rgba(124,106,247,.4)"
stroke-width="1.5" />
<text x="65" y="47" text-anchor="middle" fill="#7c6af7" font-size="10" font-weight="bold">Order
Service</text>
<text x="65" y="62" text-anchor="middle" fill="#8892a4" font-size="8">PRODUCER</text>
<rect x="10" y="85" width="110" height="40" rx="7" fill="rgba(124,106,247,.1)" stroke="rgba(124,106,247,.4)"
stroke-width="1.5" />
<text x="65" y="102" text-anchor="middle" fill="#7c6af7" font-size="10" font-weight="bold">Payment
Svc</text>
<text x="65" y="117" text-anchor="middle" fill="#8892a4" font-size="8">PRODUCER</text>
<rect x="10" y="140" width="110" height="40" rx="7" fill="rgba(124,106,247,.1)"
stroke="rgba(124,106,247,.4)" stroke-width="1.5" />
<text x="65" y="157" text-anchor="middle" fill="#7c6af7" font-size="10" font-weight="bold">Driver
Service</text>
<text x="65" y="172" text-anchor="middle" fill="#8892a4" font-size="8">PRODUCER</text>
<!-- Arrows to broker -->
<line x1="120" y1="50" x2="195" y2="95" stroke="#7c6af7" stroke-width="1.5" marker-end="url(#aev)" />
<line x1="120" y1="105" x2="195" y2="100" stroke="#7c6af7" stroke-width="1.5" marker-end="url(#aev)" />
<line x1="120" y1="160" x2="195" y2="108" stroke="#7c6af7" stroke-width="1.5" marker-end="url(#aev)" />
<text x="155" y="68" fill="#6272a4" font-size="8" transform="rotate(-15,155,68)">Publish</text>