บทที่ 19 · Message Queue

ออกแบบ Distributed Message Queue

Message Queue สำหรับ Decoupling, Scalability และ Availability ที่ดีขึ้น

บทนำ

Message Queue เป็น Component ที่คงทนซึ่งสนับสนุนการสื่อสารแบบ Asynchronous

ข้อดี

Messaging Models

Point-to-Point

Message ถูกส่งไป Queue และ Consumer เดียวรับ

Publish-Subscribe

Messages เชื่อมโยงกับ Topic และทุก Subscribers ได้รับ

Components

Data Storage

ใช้ Write-Ahead Log (WAL) - ไฟล์ข้อความที่รองรับเฉพาะการต่อท้าย

Batching

Batch Messages สำคัญสำหรับประสิทธิภาพ

Consumer Groups

กลุ่ม Consumers ทำงานด้วยกันเพื่อบริโภค Messages จาก Topic

Replication

แต่ละ Partition ถูกจำลองข้ามหลาย Brokers โดยมี Leader Replica เพียงตัวเดียว

Delivery Semantics

  • At-most-once: Messages อาจไม่ถูกส่ง
  • At-least-once: Messages ส่งอย่างน้อยหนึ่งครั้ง (อาจซ้ำ)
  • Exactly-once: Messages ส่งทุกครั้ง (แพงที่สุด)

เนื้อหานี้อ้างอิงจาก ByteByteGo - System Design Interview - An Insider's Guide