# 09 · Message Queue & Async Communication — เมื่อไม่ต้องรอคำตอบทันที

Chapter 9 of 9 in: System Design Handbook

Level 5 of 5 — ตัดการรอคำตอบ (chapter 9)

Source: https://tayakorn.dev/handbooks/system-design/message-queues-async

Updated: 2026-07-13 (whole book)

Full book: https://tayakorn.dev/handbooks/system-design.md (~62K chars)

Previous: [08 · Security & Rate Limiting — ปกป้องระบบใน Production](https://tayakorn.dev/handbooks/system-design/security-rate-limiting.md)

Also in this file, after this chapter — end matter for the whole book: รายการอ้างอิง · อ่านต่อ: Harness Engineering

---

*Sync vs Async · Message Queue · Pub/Sub · Kafka · RabbitMQ · SQS* · เนื้อหาเสริม — นอกคลิปต้นฉบับ เพิ่มเพื่อปิดช่องว่างสำคัญของ production infrastructure

ทุกบทที่ผ่านมาพูดถึงการสื่อสารแบบ **synchronous** เป็นหลัก — ผู้เรียกส่ง request แล้วรอคำตอบก่อนทำงานต่อ (บทที่ 5) แต่ไม่ใช่ทุกงานที่ต้องรอ: ส่งอีเมลยืนยัน, ตัดต่อวิดีโอ, สร้างรายงานสรุปยอดขาย — งานเหล่านี้ผู้ใช้ไม่ต้องเห็นผลทันที และถ้าให้ request หลักรอจนกว่าทุกงานจะเสร็จ ก็แค่ทำให้ระบบช้าและเปราะบางขึ้นโดยไม่จำเป็น บทนี้ว่าด้วยการสื่อสารแบบ **asynchronous** ผ่านตัวกลางที่เรียกว่า message queue

### 9.1 Synchronous vs Asynchronous — ใครรอใคร

การเรียกแบบ synchronous (ที่เห็นมาตลอดเล่มนี้ ไม่ว่า REST, GraphQL, หรือ gRPC) ผูกชะตาผู้เรียกกับผู้ถูกเรียกไว้ด้วยกัน: ถ้า service ปลายทางช้าหรือตาย ผู้เรียกก็ช้าหรือพังตามไปด้วยทันที (cascading failure) — asynchronous เปลี่ยนโจทย์โดยแทรก **ตัวกลาง (broker/queue)** ไว้ระหว่างกัน: ผู้ส่ง (producer) แค่วางข้อความไว้ในคิวแล้วทำงานต่อได้ทันที ไม่ต้องรู้ด้วยซ้ำว่าใครเป็นผู้รับ หรือผู้รับพร้อมหรือยัง

> **FIG 9.1** — Synchronous ผูกชะตา A กับ B ไว้ด้วยกันทันที ส่วน Asynchronous ใช้คิวเป็นกันชนให้ A ไปต่อได้โดยไม่ต้องรอ B
>
> ภาพนี้แสดง: เปรียบเทียบ synchronous ที่ผู้เรียกต้องรอคำตอบก่อนทำงานต่อ กับ asynchronous ที่ผู้ส่งวางข้อความไว้ในคิวแล้วทำงานต่อได้ทันทีโดยไม่ต้องรอผู้รับ

| มิติ | Synchronous | Asynchronous |
| --- | --- | --- |
| **Coupling** | แน่น — ต้องมีทั้งสองฝั่งพร้อมกัน | หลวม — ผู้รับตายชั่วคราวได้โดยผู้ส่งไม่รู้สึก |
| **Latency ที่ผู้ใช้เห็น** | รวมเวลาทุก service ที่เรียกต่อกัน | ตอบผู้ใช้ได้ทันทีที่ "รับเรื่องแล้ว" งานจริงทำเบื้องหลัง |
| **Failure** | ลามข้าม service ได้ง่าย (cascading failure) | คิวช่วยกันชน แต่ต้องออกแบบ retry/DLQ เอง |
| **เหมาะกับ** | ผู้ใช้ต้องเห็นผลทันที (เช็กสต็อกก่อนกดจ่ายเงิน) | งานที่รอได้ / ประมวลผลหนัก / ต้องแยก service ไม่ให้ผูกกัน |

### 9.2 Message Queue พื้นฐาน — Point-to-Point

รูปแบบพื้นฐานที่สุด: producer ส่งข้อความเข้าคิว แล้ว **consumer ตัวใดตัวหนึ่ง** ดึงไปประมวลผล — ถ้ามี consumer หลายตัว (competing consumers) แต่ละข้อความยังถูกประมวลผล "ครั้งเดียว" โดยตัวใดตัวหนึ่งเท่านั้น เพิ่ม consumer = เพิ่มความเร็วในการระบายงานออกจากคิว (scale-out แบบเดียวกับบทที่ 3)

คำถามที่หนีไม่พ้นของทุกระบบคิวคือ **"ข้อความส่งถึงกี่ครั้ง"**:

- **At-most-once** — ส่งแค่ครั้งเดียว ไม่ retry ถ้าหายก็หายเลย เร็วที่สุดแต่เสี่ยงข้อมูลหาย
- **At-least-once** — รับประกันว่าถึงแน่ ๆ แต่ retry อาจทำให้ consumer เห็นข้อความ **ซ้ำ** ได้ — ค่าเริ่มต้นที่ระบบส่วนใหญ่ใช้จริง
- **Exactly-once** — ฟังดูในฝัน แต่ทำได้ยากมากในระบบกระจายจริง ส่วนใหญ่ที่อ้างว่า "exactly-once" คือ at-least-once + consumer ที่ออกแบบให้ **idempotent** (แนวคิดเดียวกับ Idempotency Key ในบทที่ 4) — เรียกซ้ำกี่ครั้งผลลัพธ์เหมือนเดิม จึงไม่สำคัญว่าจะได้รับข้อความซ้ำหรือไม่

เมื่อ consumer ประมวลผลข้อความเดิมล้มเหลวซ้ำ ๆ (เช่น payload ผิดรูปเสมอ) จะปล่อยให้มันบล็อกคิวไม่ได้ — ระบบคิวที่ดีจึงมี **Dead-Letter Queue (DLQ)**: หลัง retry ครบจำนวนที่กำหนด ข้อความนั้นถูกย้ายไปพักไว้ต่างหากให้คนมาตรวจสอบ แทนที่จะวนซ้ำไม่รู้จบหรือหายไปเงียบ ๆ

### 9.3 Pub/Sub — หนึ่งข้อความ หลายผู้รับ

อีกรูปแบบคือ **Publish/Subscribe**: producer ส่งเข้า "topic" แล้ว **ทุก subscriber** ที่สนใจ topic นั้นได้รับสำเนาข้อความของตัวเอง เป็นอิสระต่อกันโดยสิ้นเชิง — ต่างจาก queue ที่ข้อความหนึ่งชิ้นมีผู้รับได้แค่รายเดียว ตัวอย่างจริง: event `order.created` หนึ่งชิ้น อาจต้องแจ้งทั้งบริการอีเมล, บริการวิเคราะห์ข้อมูล และบริการสต็อก — pub/sub ให้ทั้งสามบริการรับ event เดียวกันได้พร้อมกันโดยไม่ต้องรู้จักกันเลย เพิ่ม/ลบ subscriber ทีหลังก็ไม่กระทบ producer

> **FIG 9.2** — Queue กระจายภาระงานให้ worker หลายตัวช่วยกันทำ (แต่ละข้อความครั้งเดียว) · Pub/Sub กระจายสำเนาข้อความเดียวกันให้ subscriber ทุกตัวที่สนใจ topic นั้น
>
> ภาพนี้แสดง: เปรียบเทียบ queue แบบ point-to-point ที่แต่ละข้อความถูกประมวลผลโดย worker เพียงตัวเดียว กับ pub/sub ที่ทุก subscriber ได้รับสำเนาข้อความของตัวเองอย่างอิสระ

### 9.4 เปรียบเทียบเครื่องมือจริง — Kafka, RabbitMQ, SQS

สามชื่อที่เจอบ่อยที่สุดในงานจริง มีจุดเด่นคนละแบบ ไม่ใช่ตัวไหน "ดีที่สุด" สากล:

| มิติ | Kafka | RabbitMQ | Amazon SQS |
| --- | --- | --- | --- |
| **โมเดล** | Distributed commit log — เก็บข้อความไว้ อ่านซ้ำ/replay ได้ | Message broker แบบดั้งเดิม — ส่งแล้วลบ | Managed queue เต็มรูปแบบ ไม่ต้องดูแล infra เอง |
| **Throughput** | สูงมาก (หลักล้าน msg/วินาที) | สูง แต่ต่ำกว่า Kafka | สูงมาก แต่ latency ต่อข้อความสูงกว่า |
| **Routing** | Topic + partition, ทำ pub/sub ผ่าน consumer group หลายกลุ่ม | ยืดหยุ่นสุด (direct/topic/fanout exchange) | เรียบง่าย ต้องพ่วง SNS ถ้าอยากได้ pub/sub |
| **Ops** | ดูแลเองซับซ้อน (หรือใช้ managed เช่น Confluent/MSK) | ดูแลง่ายกว่า Kafka | แทบไม่ต้องดูแล — AWS จัดการให้ทั้งหมด |
| **เหมาะกับ** | Event sourcing, stream processing, event backbone ขนาดใหญ่ | Task queue ทั่วไป, routing ซับซ้อน, ต้องการ latency ต่ำ | ทีมที่อยู่บน AWS อยู่แล้วและอยากได้ความง่าย |

> 🧭 **เริ่มจากตรงไหนดี** — ถ้าโจทย์คือ "งานเบื้องหลังธรรมดา" (ส่งอีเมล, ประมวลผลรูป) — คิวทั่วไปแบบ SQS/RabbitMQ ก็เกินพอ อย่าเริ่มด้วย Kafka เพราะมันมาพร้อม operational overhead ที่คุ้มค่าก็ต่อเมื่อต้อง **เก็บ event ไว้ replay ได้** หรือมีทราฟฟิกระดับ stream ประมวลผลต่อเนื่องจริง ๆ — หลักการเดียวกับที่ย้ำมาตลอดเล่มนี้: เลือกเครื่องมือให้ตรงขนาดปัญหา ไม่ใช่ตามกระแส

### 9.5 ราคาที่ Async เรียกเก็บ

ความหลวมตัวที่ async ให้มา แลกมาด้วยความซับซ้อนที่ย้ายไปซ่อนอยู่จุดอื่น:

- **Ordering ไม่การันตีเสมอไป** — ข้ามหลาย partition/consumer ลำดับที่ส่งอาจไม่ตรงกับลำดับที่ประมวลผลจริง ต้องออกแบบ partition key ให้ข้อความที่ต้องเรียงกัน (เช่น event ของ order เดียวกัน) ไปอยู่ partition เดียวกันเสมอ
- **Eventual consistency แทรกซึมทั่วระบบ** — เชื่อมกับแนวคิด BASE/CAP ในบทที่ 2: service ที่ subscribe event อาจเห็นข้อมูล "ตามหลัง" อยู่เสี้ยววินาทีถึงหลักวินาทีเสมอ
- **Debug ยากขึ้น** — ไม่มี call stack เดียวให้ไล่ตามอีกต่อไป ต้องพึ่ง correlation ID / distributed tracing ติดไปกับทุกข้อความเพื่อตามรอย flow ข้าม service
- **Consumer ต้อง idempotent เสมอ** — เพราะ at-least-once คือค่าเริ่มต้นที่พบบ่อยที่สุด (9.2) การรับข้อความซ้ำคือเรื่องปกติที่ต้องออกแบบรองรับไว้ก่อน ไม่ใช่ข้อยกเว้น

> ⚠️ **อย่า async ทุกอย่าง** — Async แก้ปัญหา coupling และ availability ได้ดี แต่ไม่เหมาะกับทุกงาน — ถ้าผู้ใช้ต้องเห็นผลลัพธ์ทันที (เช่น เช็กว่ามีสต็อกพอก่อนตัดเงิน) การซ่อน logic ไว้หลังคิวมีแต่จะเพิ่มความซับซ้อนโดยไม่ได้อะไรกลับมา หลักคิดที่ใช้ได้เสมอ: **งานที่ผู้ใช้ต้องรอผลอยู่แล้วให้ sync งานที่รอได้ให้ async**

> ✅ **สรุปบทที่ 9** — Synchronous ผูก service เข้าด้วยกันแน่น async ใช้คิวเป็นกันชนตัดการพึ่งพากันโดยตรง · Queue กระจายงานให้ผู้รับหนึ่งราย (scale ด้วย worker) ส่วน Pub/Sub กระจายสำเนาให้ทุก subscriber อิสระต่อกัน · At-least-once + idempotent consumer คือค่าเริ่มต้นที่ใช้จริงในโลก ไม่ใช่ exactly-once ในฝัน · Kafka เหมาะ event streaming ขนาดใหญ่, RabbitMQ เหมาะ task queue ทั่วไป, SQS เหมาะทีมที่อยากได้ความง่ายบน AWS · async ไม่ใช่ค่าเริ่มต้นของทุกงาน — ใช้เมื่อผู้ใช้รอได้จริง ๆ เท่านั้น

*— จบหลักสูตร —*

## รายการอ้างอิง

เรียงตามลำดับที่ปรากฏครั้งแรกในเล่ม มาตรฐาน RFC อ้างฉบับที่ใช้อยู่ ณ วันที่ตรวจ ส่วนเอกสารของผลิตภัณฑ์ (Redis · Stripe · GitHub · AWS · Kafka · RabbitMQ) เปลี่ยนตามรุ่นและไม่ปักฉบับ ทุกหน้าอ่านจากฉบับที่เปิดอยู่ตอนตรวจ คือ 4 พฤศจิกายน 2026 · ทุกรายการเปิดอ่านได้ฟรีทั้งหน้า ยกเว้นที่ระบุไว้ท้ายรายการ

1. Simonyan H. **System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra.** YouTube · [youtube.com](https://www.youtube.com/watch?v=oYxTTirKY8M) — บทที่ 1–8 · คลิปต้นฉบับที่เล่มนี้เรียบเรียง (บทที่ 9 เป็นเนื้อหาเสริมนอกคลิป)
2. Redis. **Key eviction.** Redis Docs · [redis.io/docs](https://redis.io/docs/latest/develop/reference/eviction/) — บทที่ 1 · นโยบาย `allkeys-lru` ทิ้ง key ที่ถูกใช้ล่าสุดนานที่สุดเมื่อหน่วยความจำเต็ม
3. WonderNetwork. **Ping time between Bangkok and Singapore** และ **Bangkok and Los Angeles.** ค่าวัดสดรายชั่วโมง · [กรุงเทพฯ–สิงคโปร์](https://wondernetwork.com/pings/Bangkok/Singapore) · [กรุงเทพฯ–ลอสแอนเจลิส](https://wondernetwork.com/pings/Bangkok/Los%20Angeles) — บทที่ 1 · ใช้ยันขนาดของตัวเลข ~30ms กับ ~250ms ณ วันที่ตรวจ ค่าเฉลี่ยราว 23 ms และราว 196–242 ms ตามลำดับ (ค่าเปลี่ยนทุกชั่วโมง)
4. Haerder T, Reuter A. **Principles of Transaction-Oriented Database Recovery.** *ACM Computing Surveys* 1983;15(4):287–317 · [doi:10.1145/289.291](https://doi.org/10.1145/289.291) — บทที่ 2 · งานที่ตั้งชื่อ ACID (atomicity · consistency · isolation · durability) · หน้า ACM บล็อกการเข้าถึงอัตโนมัติ ยันเนื้อจากสำเนาในหน้ารายวิชาของมหาวิทยาลัย
5. Pritchett D. **BASE: An Acid Alternative.** *ACM Queue* 2008;6(3):48–55 · [doi:10.1145/1394127.1394128](https://doi.org/10.1145/1394127.1394128) — บทที่ 2 · ที่มาของคำว่า BASE · ยืนยันได้เฉพาะข้อมูลบรรณานุกรมผ่าน Crossref (หน้าบทความบล็อกการเข้าถึงอัตโนมัติ)
6. Gilbert S, Lynch N. **Brewer's conjecture and the feasibility of consistent, available, partition-tolerant web services.** *ACM SIGACT News* 2002;33(2):51–59 · [doi:10.1145/564585.564601](https://doi.org/10.1145/564585.564601) — บทที่ 2 · บทพิสูจน์ CAP ฉบับรูปนัย · ยืนยันได้เฉพาะข้อมูลบรรณานุกรมผ่าน Crossref
7. Brewer E. **CAP Twelve Years Later: How the "Rules" Have Changed.** *Computer* 2012;45(2):23–29 · [doi:10.1109/MC.2012.37](https://doi.org/10.1109/MC.2012.37) · [ฉบับเต็มที่ InfoQ เผยแพร่ร่วมกับ IEEE Computer Society](https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/) — บทที่ 2, 9 · กรอบ "ตอน partition ต้องเลือกระหว่าง consistency กับ availability" ที่เล่มใช้
8. PostgreSQL Global Development Group. **8.14. JSON Types.** PostgreSQL 18 Documentation · [postgresql.org/docs](https://www.postgresql.org/docs/current/datatype-json.html) — บทที่ 2 · ชนิดข้อมูล `json` และ `jsonb`
9. Garcia-Molina H, Salem K. **Sagas.** *Proceedings of ACM SIGMOD* 1987:249–259 · [doi:10.1145/38713.38742](https://doi.org/10.1145/38713.38742) — บทที่ 2 · งานต้นทางของ saga: ธุรกรรมยาวที่เขียนเป็นลำดับธุรกรรมย่อยพร้อม compensating transaction
10. Richardson C. **Pattern: Saga.** microservices.io · [microservices.io](https://microservices.io/patterns/data/saga.html) — บทที่ 2 · saga ข้าม service สองแบบ: choreography กับ orchestration
11. Richardson C. **Pattern: Transactional outbox.** microservices.io · [microservices.io](https://microservices.io/patterns/data/transactional-outbox.html) — บทที่ 2 · เขียนข้อมูลกับ event ลงตาราง outbox ใน transaction เดียว แล้วให้อีก process ส่งต่อ
12. Google. **Site Reliability Engineering** บทที่ 3 Embracing Risk (เขียนโดย Marc Alvidrez) และภาคผนวก A Availability Table. Google/O'Reilly ฉบับอ่านออนไลน์ · [sre.google · Embracing Risk](https://sre.google/sre-book/embracing-risk/) · [sre.google · Availability Table](https://sre.google/sre-book/availability-table/) — บทที่ 3 · ตาราง downtime ต่อปีของแต่ละระดับ nines และต้นทุนที่โตเร็วกว่าเส้นตรงเมื่อไล่ความน่าเชื่อถือเพิ่ม
13. Karger D, Lehman E, Leighton T, Panigrahy R, Levine M, Lewin D. **Consistent Hashing and Random Trees: Distributed Caching Protocols for Relieving Hot Spots on the World Wide Web.** *Proceedings of ACM STOC* 1997:654–663 · [doi:10.1145/258533.258660](https://doi.org/10.1145/258533.258660) — บทที่ 3 · งานต้นทางของ consistent hashing · ยันเนื้อจากสำเนาในหน้ารายวิชาของมหาวิทยาลัย
14. Fielding R, Nottingham M, Reschke J (บรรณาธิการ). **HTTP Semantics.** RFC 9110 (STD 97) มิถุนายน 2022 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9110.html) — บทที่ 4, 5, 7, 8 · นิยาม idempotent (PUT · DELETE และ method ที่ safe) · ความหมายของ status code 201 · 204 · 401 · 403 · 503 · header `Retry-After`
15. Dusseault L, Snell J. **PATCH Method for HTTP.** RFC 5789 มีนาคม 2010 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc5789.html) — บทที่ 4 · PATCH ไม่ได้เป็น idempotent โดยนิยาม แต่ออกแบบคำขอให้เป็นได้
16. Stripe. **Idempotent requests.** Stripe API Reference · [docs.stripe.com](https://docs.stripe.com/api/idempotent_requests) — บทที่ 4 · header `Idempotency-Key` · ทุก POST ของ API v1 รับ idempotency key
17. Nottingham M, Fielding R. **Additional HTTP Status Codes.** RFC 6585 เมษายน 2012 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc6585.html) — บทที่ 4, 8 · นิยาม `429 Too Many Requests` ที่แนบ `Retry-After` ได้
18. Eddy W (บรรณาธิการ). **Transmission Control Protocol (TCP).** RFC 9293 (STD 7) สิงหาคม 2022 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9293.html) — บทที่ 5 · three-way handshake และการตอบรับ/ส่งซ้ำ
19. Bishop M (บรรณาธิการ). **HTTP/3.** RFC 9114 มิถุนายน 2022 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9114.html) — บทที่ 5 · HTTP บน QUIC
20. Iyengar J, Thomson M (บรรณาธิการ). **QUIC: A UDP-Based Multiplexed and Secure Transport.** RFC 9000 พฤษภาคม 2021 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9000.html) — บทที่ 5 · QUIC สร้างบน UDP
21. Cloudflare. **HTTP/3: the past, the present, and the future.** Cloudflare Blog 26 กันยายน 2019 · [blog.cloudflare.com](https://blog.cloudflare.com/http3-the-past-present-and-future/) — บทที่ 5 · Cloudflare เปิดรองรับ HTTP/3 และทำงานร่วมกับ Google และ Mozilla ในการทำมาตรฐาน
22. WHATWG. **9.2 Server-sent events.** HTML Living Standard · [html.spec.whatwg.org](https://html.spec.whatwg.org/multipage/server-sent-events.html) — บทที่ 5 · `EventSource` สตรีมข้อความทางเดียวจากเซิร์ฟเวอร์
23. Fette I, Melnikov A. **The WebSocket Protocol.** RFC 6455 ธันวาคม 2011 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc6455.html) — บทที่ 5 · ท่อสองทางที่เริ่มจาก handshake แบบ HTTP
24. Byron L. **GraphQL: A data query language.** Engineering at Meta 14 กันยายน 2015 · [engineering.fb.com](https://engineering.fb.com/2015/09/14/core-infra/graphql-a-data-query-language/) — บทที่ 6 · Facebook สร้าง GraphQL ในปี 2012 เพื่อแอปมือถือ (News Feed บน iOS) และประกาศสเปกกับ reference implementation ในปี 2015
25. GraphQL Foundation. **GraphQL Specification** (October 2021 Edition) · [spec.graphql.org](https://spec.graphql.org/October2021/) — บทที่ 6 · ระบบ type และปฏิบัติการสามชนิด query · mutation · subscription
26. GraphQL Foundation. **DataLoader.** GitHub · [github.com/graphql/dataloader](https://github.com/graphql/dataloader) — บทที่ 6 · batching และ caching ลดคำขอซ้ำจาก resolver
27. gRPC Authors. **Introduction to gRPC** และ **FAQ.** grpc.io · [grpc.io · Introduction](https://grpc.io/docs/what-is-grpc/introduction/) · [grpc.io · FAQ](https://grpc.io/docs/what-is-grpc/faq/) — บทที่ 6 · Protocol Buffers · ทำงานบน HTTP/2 · รองรับ streaming สองทาง
28. GitHub. **The GitHub GraphQL API.** The GitHub Blog 14 กันยายน 2016 · [github.blog](https://github.blog/developer-skills/github/the-github-graphql-api/) — บทที่ 6 · GitHub เปิด GraphQL API ในปี 2016
29. GitHub. **Comparing GitHub's REST API and GraphQL API.** GitHub Docs · [docs.github.com](https://docs.github.com/en/rest/about-the-rest-api/comparing-githubs-rest-api-and-graphql-api) — บทที่ 6 · บางฟีเจอร์รองรับบน API เดียว ไม่ใช่ทั้งสอง
30. Jones M, Bradley J, Sakimura N. **JSON Web Token (JWT).** RFC 7519 พฤษภาคม 2015 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc7519.html) — บทที่ 7 · โครงสามส่วนคั่นด้วยจุด และ claim `exp`
31. Jones M, Hardt D. **The OAuth 2.0 Authorization Framework: Bearer Token Usage.** RFC 6750 ตุลาคม 2012 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc6750.html) — บทที่ 7 · รูปแบบ header `Authorization: Bearer`
32. Hardt D (บรรณาธิการ). **The OAuth 2.0 Authorization Framework.** RFC 6749 ตุลาคม 2012 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc6749.html) — บทที่ 7 · สี่บทบาท resource owner · client · authorization server · resource server และ scope
33. Sakimura N, Bradley J, Agarwal N. **Proof Key for Code Exchange by OAuth Public Clients.** RFC 7636 กันยายน 2015 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc7636.html) — บทที่ 7 · PKCE ใช้คู่ code verifier/challenge กันการดัก authorization code
34. Lodderstedt T, Bradley J, Labunets A, Fett D. **Best Current Practice for OAuth 2.0 Security.** RFC 9700 (BCP 240) มกราคม 2025 · [rfc-editor.org](https://www.rfc-editor.org/rfc/rfc9700.html) — บทที่ 7 · public client ต้องใช้ PKCE
35. OpenID Foundation. **OpenID Connect Core 1.0** incorporating errata set 2 · [openid.net](https://openid.net/specs/openid-connect-core-1_0.html) — บทที่ 7 · ID Token เป็น JWT ที่บรรจุ claim การยืนยันตัวตน
36. Hu V, Ferraiolo D, Kuhn R, et al. **Guide to Attribute Based Access Control (ABAC) Definition and Considerations.** NIST SP 800-162 มกราคม 2014 (ปรับปรุงถึง 2 สิงหาคม 2019) · [csrc.nist.gov](https://csrc.nist.gov/pubs/sp/800/162/upd2/final) — บทที่ 7 · นิยาม ABAC เทียบกับการคุมสิทธิ์ตามบทบาท
37. AWS. **Throttle requests to your REST APIs for better throughput in API Gateway.** Amazon API Gateway Developer Guide · [docs.aws.amazon.com](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-throttling.html) — บทที่ 8 · API Gateway ใช้ token bucket (rate = อัตราเติม token · burst = ความจุถัง) และตอบ 429 เมื่อเกิน
38. GitHub. **Rate limits for the REST API.** GitHub Docs · [docs.github.com](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api) — บทที่ 8 · header `x-ratelimit-limit` · `x-ratelimit-remaining` · `x-ratelimit-reset` (UTC epoch seconds) และ `retry-after`
39. Brooker M. **Exponential Backoff And Jitter.** AWS Architecture Blog 4 มีนาคม 2015 (ปรับปรุงพฤษภาคม 2023) · [aws.amazon.com/blogs](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/) — บทที่ 8 · backoff อย่างเดียวยังทำให้ client retry เป็นกลุ่ม ต้องเติม jitter
40. OWASP. **Password Storage Cheat Sheet.** OWASP Cheat Sheet Series · [cheatsheetseries.owasp.org](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) — บทที่ 8 · ใช้ Argon2id · scrypt · bcrypt · PBKDF2 ไม่ใช้ hash ที่ออกแบบให้เร็วอย่าง MD5 · SHA-1
41. Apache Software Foundation. **Introduction** และ **Design.** Apache Kafka 4.4 Documentation · [kafka.apache.org · Introduction](https://kafka.apache.org/44/getting-started/introduction/) · [kafka.apache.org · Design](https://kafka.apache.org/44/design/design/) — บทที่ 9 · at-most-once · at-least-once · exactly-once · event ไม่ถูกลบหลังอ่านจึงอ่านซ้ำได้ · ลำดับรับประกันภายใน partition · partition ละหนึ่ง consumer ต่อ consumer group
42. AWS. **Amazon SQS at-least-once delivery** และ **Using dead-letter queues in Amazon SQS.** Amazon SQS Developer Guide · [docs.aws.amazon.com · at-least-once](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues-at-least-once-delivery.html) · [docs.aws.amazon.com · DLQ](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html) — บทที่ 9 · ข้อความอาจมาซ้ำ ให้ออกแบบ consumer เป็น idempotent · `maxReceiveCount` ก่อนย้ายเข้า DLQ
43. Kreps J. **Benchmarking Apache Kafka: 2 Million Writes Per Second (On Three Cheap Machines).** LinkedIn Engineering 27 เมษายน 2014 · [engineering.linkedin.com](https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines) — บทที่ 9 · ที่มาของ throughput ระดับล้านข้อความต่อวินาที
44. Broadcom. **AMQP 0-9-1 Model Explained.** RabbitMQ Documentation · [rabbitmq.com](https://www.rabbitmq.com/tutorials/amqp-concepts) — บทที่ 9 · exchange แบบ direct · fanout · topic · headers
45. AWS. **Fanout Amazon SNS notifications to Amazon SQS queues for asynchronous processing.** Amazon SNS Developer Guide · [docs.aws.amazon.com](https://docs.aws.amazon.com/sns/latest/dg/sns-sqs-as-subscriber.html) — บทที่ 9 · pub/sub บน AWS ทำด้วย SNS กระจายเข้าคิว SQS

## อ่านต่อ: Harness Engineering

> 💡 **[handbook แนะนำ] ทำไมเล่มนี้** — เล่มนี้ปิดท้ายด้วยเช็กลิสต์ป้องกันระบบจาก client ที่ไม่น่าไว้ใจ — rate limit, auth, defense in depth แต่ถ้า client ที่เรียก API ของคุณไม่ใช่มนุษย์อีกต่อไป แต่เป็น AI agent ที่เรียกซ้ำเป็นพันครั้งต่อนาทีล่ะ? Harness Engineering พาแนวคิดการ์ดระบบแบบเดียวกันนี้ไปใช้ออกแบบระบบรอบ AI agent — guardrails, observability, stop conditions สำหรับผู้ใช้ประเภทใหม่ที่คาดเดายากกว่ามนุษย์ · **[เปิดอ่าน Harness Engineering Handbook →](/handbooks/harness-engineering)**

---

**System Design Handbook** — เรียบเรียงจากคอร์ส "System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra" โดย Hayk Simonyan — [เปิดคลิปบน YouTube](https://www.youtube.com/watch?v=oYxTTirKY8M)

วิธีใช้เอกสารนี้ให้คุ้ม: อ่านทีละบทคู่กับช่วงเวลาในคลิป → วาดไดอะแกรมซ้ำด้วยมือเปล่า → ลองออกแบบระบบจริง (เช่น URL shortener, ระบบแชต) โดยใช้ครบทุกบท