Event-Driven Architecture (EDA) là kiến trúc nơi các components giao tiếp với nhau qua events (notifications về điều gì đó đã xảy ra) thay vì direct API calls. Producer emit events mà không biết consumer là ai; consumer subscribe và xử lý events async – đạt được loose coupling cao.
Lợi ích: producers và consumers hoàn toàn độc lập (có thể deploy, scale, fail độc lập), dễ thêm consumer mới mà không sửa producer, natural fit cho audit logging và event sourcing, handle high throughput tốt qua buffering. Thách thức: debugging và tracing khó hơn vì flow phi tuyến tính; eventual consistency – consumer có thể xử lý chậm hơn producer; ordering guarantees phức tạp (Kafka đảm bảo ordering trong partition); idempotency – consumer cần handle duplicate events; schema evolution khi event format thay đổi. Patterns quan trọng: dead letter queue cho failed events, event schema registry (Confluent Schema Registry), outbox pattern để đảm bảo atomicity giữa DB write và event publish.
Event-Driven Architecture (EDA) is an architectural style where components communicate via events (notifications that something has happened) rather than direct API calls. Producers emit events without knowing who the consumers are; consumers subscribe and process events asynchronously — achieving high loose coupling.
Benefits: producers and consumers are fully independent (can be deployed, scaled, and fail independently); new consumers can be added without modifying producers; it is a natural fit for audit logging and event sourcing; high throughput is handled well through buffering. Challenges: debugging and tracing are harder due to non-linear flows; eventual consistency — consumers may process events more slowly than producers; ordering guarantees are complex (Kafka ensures ordering within a partition); idempotency — consumers must handle duplicate events; schema evolution when the event format changes. Key patterns: dead letter queues for failed events, event schema registries (Confluent Schema Registry), and the outbox pattern to ensure atomicity between a database write and an event publish.