Part 08 · Architecture Decision · 8.1.10

Chọn broker và vận hành production

Chọn theo semantics, failure model và operational burden của workload — không theo độ phổ biến, benchmark marketing hay mong muốn chuẩn hóa một công nghệ cho mọi flow.

Decision rule: bắt đầu từ routing, ownership, retention/replay, ordering, throughput, latency, loss/duplicate tolerance và đội ngũ vận hành. Broker là một phần của protocol, không phải generic transport hoán đổi miễn phí.

1. RabbitMQ và Kafka thiên về gì?

Nhu cầuRabbitMQ thiên vềKafka thiên về
Work queue / command dispatchQueue ownership, ack, flexible routingCó thể làm nhưng offset/log model khác
Per-message routingDirect/topic/fanout/headers exchangesTopic + partition key đơn giản hơn
Retention và replayKhông phải core consumption modelCore strength, offsets độc lập
Nhiều independent consumersBindings tạo queue copiesNhiều groups đọc cùng log
Delay/TTL/DLXPrimitives tích hợp/policyRetry topics/processors/scheduler
Stream processingApplication tự xây nhiều hơnLog/partition/transaction ecosystem
Fine-grained queue priorityCó queue features phù hợp workloadThường model bằng topics/consumers
OrderingRàng buộc queue/channel; cần kiểm tra concurrency và redeliveryPer partition, không phải toàn topic

Đây là khuynh hướng, không phải “có/không” tuyệt đối. POC phải bao gồm failure, backpressure, security và recovery; happy-path throughput không đủ để quyết định.

Follow-up · Jobs, audit events và notifications

Choose RabbitMQ or Kafka for jobs, audit events and notifications.

Dùng cùng decision matrix cho cả ba workload. Với notifications, nêu rõ routing/fan-out, retention/replay, ordering và cách xử lý duplicate ở side effect. Ghi lại assumptions và lý do chọn broker, không chỉ nêu tên công nghệ.

Đây là follow-up của câu 23–24 trong bộ 30 câu hỏi, không phải câu hỏi hay lab mới.

2. Requirement và semantics checklist

Exactly-once không phải checkbox broker. Nếu workflow chạm database/payment/email, phải mô tả atomic boundary, idempotency và reconciliation ngoài broker.

3. Capacity model và SLO

Ước lượng steady/burst message rate, payload distribution, routing fan-out, compression, retention/backlog, replication, producer confirms/acks, consumer service time và recovery catch-up. Capacity phải còn headroom khi một node/AZ mất hoặc khi reassign/compact/replay.

SLO nên gồm publish availability/latency, end-to-end processing age, loss/duplicate tolerance, retry/DLQ age, replay throughput và recovery RTO. Benchmark cùng TLS, auth, durability, schema, client batching và payload thật.

4. Security, governance và data lifecycle

Dùng TLS, authentication, least privilege theo vhost/exchange/queue hoặc topic/group/transactional ID, credential rotation, quotas và audit. Hạn chế management/admin APIs và không cho ứng dụng tùy ý tạo topology/topic production.

Message chứa PII/secret cần minimization, encryption-at-rest/in-transit theo threat model, retention/deletion và access audit. Encryption không thay authorization; schema registry, connectors và monitoring endpoints cũng thuộc attack surface.

5. Incident diagnosis patterns

Triệu chứngPhân biệtAction đầu tiên
Backlog/lag tăngIngress spike, slow consumer/downstream, skew, broker saturationStop amplification, đo per queue/partition age/rate
Rebalance stormPoll timeout, GC, network, deploy churnStabilize membership và bounded processing
DLQ spikeSchema/permanent/transient/permissionDừng replay, classify sample, bảo vệ downstream
Publish latencyBroker alarm, ISR/quorum, disk/network, client bufferGiảm ingress và bảo vệ durability
Hot partition/leaderKey skew, placement, single queue workloadConfirm distribution trước khi rebalance

6. Migration và coexistence

Dual publish trực tiếp từ business transaction dễ diverge khi một broker thành công và broker kia fail. Dùng outbox/relay, stable event ID và reconciliation ledger. Backfill/replay phải giữ key/order, schema version, rate limit và downstream idempotency.

Thiết kế shadow consumer để so count/content/order trước cutover; canary producer/consumer; define source of truth trong từng phase; giữ rollback không tạo double processing. Không đổi broker nếu chưa lượng hóa requirement hiện tại không đáp ứng hoặc operational cost cải thiện.

Review checklist: decision matrix gắn workload; SLO có age/loss/duplicate/replay; benchmark production-like; permissions/quotas/lifecycle rõ; incident runbook phân loại nguyên nhân; migration có outbox, reconciliation, canary và rollback.
Tài liệu: RabbitMQ Production Checklist · RabbitMQ Security · Kafka Operations · Kafka Security · Kafka Cluster Expansion