Logo Architecture Event Driven

Architecture Event Driven

Cộng đồng
j4flmao
architecture-event-driven

Use this skill when the user says 'event-driven architecture', 'EDA', 'pub/sub between services', 'domain events', 'Kafka vs RabbitMQ vs SQS', 'dual write', 'transactional outbox', 'event schema', 'eventual consistency', 'choreography'. Designs asynchronous service integration: event vs command semantics, broker choice, delivery guarantees, outbox/inbox, ordering and partitioning, schema evolution, and tracing. Do NOT use for: implementation recipes inside one backend stack (backend/universal/event-driven, backend/universal/transactional-outbox), event sourcing as a persistence model (backend/universal/event-sourcing), or stream analytics (data/streaming).

Tổng quan

Nhà phát hànhj4flmao
Kho mãagent-skills
Tên kỹ năngarchitecture-event-driven
Sao
41
Bản fork
6
Tệp đi kèm
1
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 1 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được j4flmao công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Architecture Event Driven trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/j4flmao/agent-skills/tree/main/skills/architecture/event-driven
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/architecture/event-driven .claude/skills/architecture-event-driven
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Architecture Event Driven trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Architecture Event Driven ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Architecture Event Driven với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Event-Driven Architecture

Purpose

In EDA, services publish facts ("OrderPlaced") and other services react, so producers do not depend on consumers being available or even known. The price is eventual consistency, harder debugging, and the need for reliable publishing and idempotent consumption. This skill covers the architectural decisions that make EDA correct, not just decoupled.

Agent Protocol

Trigger

"event-driven", "EDA", "domain events", "pub/sub", "message broker choice", "dual-write problem", "outbox", "at-least-once", "event ordering", "event versioning", "choreography".

Input Context

  • Business flows and which steps must be synchronous for the user.
  • Throughput, ordering needs (per entity?), retention/replay needs.
  • Existing infra (Kafka, RabbitMQ, cloud queues) and team experience.
  • Consistency requirements and failure tolerance.

Output Artifact

Event catalog, broker/topology choice, delivery and idempotency design, schema/versioning policy, observability plan.

Response Format

Event: {Name}(past tense) v{n}  Producer: {service}  Consumers: {services}
Key (ordering): {aggregate id}  Topic/queue: {name}  Retention: {duration}
Publish: outbox -> {relay: CDC|poller}  Delivery: at-least-once
Consumer: idempotent via {inbox table|natural upsert}; DLQ: {name}
Schema: {Avro|Protobuf|JSON Schema} compatibility={BACKWARD}

Completion Criteria

  • Each message classified as event (fact) or command (request).
  • No dual writes: outbox or CDC for publishing.
  • Consumers idempotent; DLQ and retry policy defined.
  • Ordering key chosen per aggregate where order matters.
  • Trace context propagated in message headers.

Events vs Commands vs Queries

KindMeaningAddressed toCan be rejected?Transport
Event"OrderPlaced" happenedAnyone interestedNo (it is a fact)Topic / pub-sub
Command"ReserveStock" pleaseOne ownerYesQueue or RPC
Query"What is the stock?"One ownern/aSync RPC

Event payload style: thin events (id + type; consumers call back for details) couple consumers to the producer API at read time; fat/event-carried state transfer (include the relevant data) lets consumers build local read models. Prefer fat events for integration, scoped to what consumers need.

Broker Choice

BrokerModelStrengthsWatch out
Kafka (or Redpanda)Partitioned replicated logReplay, high throughput, per-partition order, many consumer groupsOps complexity; ordering only within a partition
RabbitMQQueues with exchanges/routingFlexible routing, per-message acks, prioritiesReplay limited (streams feature helps)
AWS SNS + SQSFan-out topic → queuesManaged, simpleStandard queues unordered; FIFO queues have lower throughput
Google Pub/Sub, Azure Service Bus/Event HubsManaged pub/sub / logManaged scalingProvider-specific semantics
NATS JetStreamStreams + consumersLightweight, low latencySmaller ecosystem

Reliable Publishing: Transactional Outbox

Writing to the database and the broker separately can lose or invent events when one write fails. Write the event to an outbox table in the same transaction as the state change, then relay it.

sql
CREATE TABLE outbox (
  id            BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  event_id      UUID NOT NULL UNIQUE,          -- consumers dedupe on this
  aggregate_id  TEXT NOT NULL,                 -- becomes the message key
  event_type    TEXT NOT NULL,
  payload       JSONB NOT NULL,
  created_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
  published_at  TIMESTAMPTZ
);

BEGIN;
INSERT INTO orders (id, customer_id, total_cents) VALUES ($1, $2, $3);
INSERT INTO outbox (event_id, aggregate_id, event_type, payload)
VALUES ($4, $1, 'OrderPlaced.v1', $5);
COMMIT;

Relay options:

  • CDC (Debezium reading the WAL, with its outbox event router): low latency, no polling load.
  • Poller: SELECT ... WHERE published_at IS NULL ORDER BY id LIMIT 100 FOR UPDATE SKIP LOCKED, publish, then mark published. Simple; a crash between publish and mark causes a duplicate, which consumers must tolerate.

Either way delivery is at-least-once, never exactly-once end to end.

Idempotent Consumers (Inbox)

python
def handle(message, conn) -> None:
    event_id = message.headers["event_id"]
    with conn.transaction():
        inserted = conn.execute(
            "INSERT INTO inbox (event_id, received_at) VALUES (%s, now()) ON CONFLICT DO NOTHING",
            (event_id,),
        ).rowcount
        if inserted == 0:
            return                      # duplicate: already processed
        apply_business_change(conn, message.value)
    # commit offset / ack only after the transaction commits

Retry transient failures with bounded backoff; route poison messages to a dead-letter queue with the error attached; alert on DLQ depth.

Ordering and Partitioning

  • Order is only guaranteed within a partition/queue; use the aggregate id as the key so all events for one order land in order.
  • Consumers must not assume global order across aggregates.
  • Carry a per-aggregate version/sequence number so consumers can detect gaps or stale events.

Schema and Versioning

  • Use a schema registry (Avro/Protobuf/JSON Schema) with compatibility checks in CI.
  • Additive changes only (new optional fields); breaking change = new event type/version (OrderPlaced.v2), dual-publish during migration.
  • Standard envelope: CloudEvents attributes (id, source, type, specversion, time, subject) plus W3C traceparent header.

Observability

Propagate trace context through message headers (OpenTelemetry messaging conventions) so one trace links the HTTP request, the outbox relay, and every consumer. Track consumer lag, DLQ depth, and end-to-end latency (event time → processed time).

Hazards

HazardMitigation
Event pinball (chains across many services)Distributed tracing; prefer an orchestrated saga for multi-step business processes
Eventual consistency surprises in UIOptimistic UI, read-your-writes from the owning service, status polling or push
Consumer coupling to producer internalsPublish integration events, not table-row changes
Unbounded retries blocking a partitionRetry topics / DLQ with backoff
Lost events from dual writesOutbox or CDC only

Checklist

  • Event catalog with owners, keys, schemas, consumers.
  • Outbox/CDC publishing; no direct broker write inside business transactions.
  • Inbox or natural idempotency on every consumer.
  • DLQ + alerting; replay procedure documented.
  • Schema registry and compatibility gate.
  • Tracing headers and lag dashboards.

References

  • CQRS & Event Sourcing — read models and event-sourced aggregates.
  • Richardson, "Microservices Patterns" — transactional outbox, saga.
  • Debezium documentation: outbox event router; CloudEvents specification (CNCF).

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Architecture Event Driven làm được gì?

Use this skill when the user says 'event-driven architecture', 'EDA', 'pub/sub between services', 'domain events', 'Kafka vs RabbitMQ vs SQS', 'dual write', 'transactional outbox', 'event schema', 'eventual consistency', 'choreography'. Designs asynchronous service integration: event vs command semantics, broker choice, delivery guarantees, outbox/inbox, ordering and partitioning, schema evolution, and tracing. Do NOT use for: implementation recipes inside one backend stack (backend/universal/event-driven, backend/universal/transactional-outbox), event sourcing as a persistence model (backe...

Vì sao nên dùng Architecture Event Driven trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Architecture Event Driven là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Architecture Event Driven trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/j4flmao/agent-skills/tree/main/skills/architecture/event-driven. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Architecture Event Driven?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Architecture Event Driven với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Architecture Event Driven với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Architecture Event Driven có miễn phí không?

Có. Kỹ năng này được j4flmao phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇