Logo Backend Event Driven Architecture

Backend Event Driven Architecture

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

Use this skill when the user says 'event-driven architecture', 'EDA', 'publish domain events', 'kafka producer', 'kafka consumer', 'rabbitmq exchange', 'event broker', 'at-least-once delivery', 'event ordering', 'consumer group'. Designs broker-based event flows (Kafka or RabbitMQ): event shape, topic/exchange layout, partitioning for ordering, delivery guarantees, consumer idempotency, retries and dead-lettering, with working producer/consumer code. Do NOT use for: event sourcing as a persistence model (backend-event-sourcing), broker operations and tuning (backend-message-queue), reliable publish from a DB transaction (backend-transactional-outbox), stream processing with Flink/Kafka Streams (backend-data-streaming).

Tổng quan

Nhà phát hànhj4flmao
Kho mãagent-skills
Tên kỹ năngbackend-event-driven-architecture
Sao
41
Bản fork
6
Tệp đi kèm
Chỉ có hướng dẫn
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ộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • 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 Backend Event Driven Architecture 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/backend/event-driven-architecture
  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/backend/event-driven-architecture .claude/skills/backend-event-driven-architecture
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 Backend Event Driven Architecture 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 Backend Event Driven Architecture 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 Backend Event Driven Architecture 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

Decouple services by having producers publish facts ("OrderPlaced") to a broker and consumers react independently. The skill covers the design decisions that make this reliable in practice: what goes in an event, how ordering and delivery guarantees work, and how consumers stay correct under redelivery.

Agent Protocol

Trigger

Exact user phrases: "event-driven architecture", "EDA", "publish domain events", "kafka producer", "kafka consumer", "rabbitmq exchange", "event broker", "at-least-once delivery", "event ordering", "consumer group".

Input Context

  • Business flow and which services produce/consume.
  • Broker in use or candidates (Kafka, RabbitMQ, cloud: SNS/SQS, Pub/Sub, Event Hubs).
  • Ordering, latency and replay requirements.
  • Language and client library.

Output Artifact

Event catalogue, topology (topics/exchanges, keys, consumer groups), and producer/consumer code. No files unless requested.

Response Format

Event: {PastTenseName} v{n}   Key: {partition key}
Topic/Exchange: {name}         Producers: {svc}   Consumers: {svc,...}
Delivery: at-least-once        Ordering: per {key}
Consumer idempotency: {dedupe table | natural upsert}
Failure: retry {n} with backoff -> DLQ {name}

Core Concepts

ConceptMeaning
Event notificationThin event ("OrderPlaced id=42"); consumers call back for details. Low coupling on schema, higher coupling at runtime
Event-carried state transferEvent carries the data consumers need; no callback; larger payloads, schema is a contract
Command vs eventCommand = request to one handler ("ChargeCard"); event = fact for any number of subscribers ("PaymentCaptured")
Delivery guaranteeBrokers give at-most-once or at-least-once to consumers. "Exactly-once" end to end requires idempotent consumers or transactional read-process-write inside one system (Kafka transactions)

Broker Choice

NeedKafkaRabbitMQ
Replay history / new consumers reading the pastYes (retention-based log)No by default (queues delete on ack); RabbitMQ Streams add a log
Per-key ordering at scaleYes, per partitionPer queue, single active consumer needed for strict order
Flexible routing (topic/headers patterns)Limited (topic per event type)Rich (direct, topic, fanout, headers exchanges)
Per-message TTL, priority, delayed retryNot nativeNative (TTL, priority queues, DLX)
Very high throughput fan-outStrongGood, lower ceiling

Event Design Rules

  1. Name events in past tense for facts that already happened (OrderPlaced, not PlaceOrder).
  2. Include an envelope: event_id (unique, for dedupe), type, version, occurred_at, source, subject/aggregate_id, optional trace_id. CloudEvents is a standard envelope worth adopting.
  3. Choose the partition key = aggregate ID so all events for one entity are ordered.
  4. Evolve schemas backward-compatibly (add optional fields only); use a schema registry (Avro/Protobuf/JSON Schema) for Kafka.
  5. Publish only after the state change is durable. Writing to the DB and the broker in one request without the outbox pattern creates dual-write inconsistencies.

Kafka Producer (Go, confluent-kafka-go v2)

go
package events

import (
	"encoding/json"
	"fmt"

	"github.com/confluentinc/confluent-kafka-go/v2/kafka"
)

type OrderPlaced struct {
	EventID    string `json:"event_id"`
	OrderID    string `json:"order_id"`
	CustomerID string `json:"customer_id"`
	TotalCents int64  `json:"total_cents"`
	OccurredAt string `json:"occurred_at"`
}

func NewProducer(brokers string) (*kafka.Producer, error) {
	return kafka.NewProducer(&kafka.ConfigMap{
		"bootstrap.servers":  brokers,
		"acks":               "all", // wait for in-sync replicas
		"enable.idempotence": true,  // no duplicates from producer retries
		"linger.ms":          5,
	})
}

// PublishOrderPlaced blocks until the broker acknowledges the write.
func PublishOrderPlaced(p *kafka.Producer, topic string, evt OrderPlaced) error {
	payload, err := json.Marshal(evt)
	if err != nil {
		return fmt.Errorf("marshal event %s: %w", evt.EventID, err)
	}
	delivery := make(chan kafka.Event, 1)
	err = p.Produce(&kafka.Message{
		TopicPartition: kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny},
		Key:            []byte(evt.OrderID), // per-order ordering
		Value:          payload,
		Headers:        []kafka.Header{{Key: "type", Value: []byte("OrderPlaced.v1")}},
	}, delivery)
	if err != nil {
		return fmt.Errorf("enqueue event %s: %w", evt.EventID, err)
	}
	m := (<-delivery).(*kafka.Message)
	if m.TopicPartition.Error != nil {
		return fmt.Errorf("deliver event %s: %w", evt.EventID, m.TopicPartition.Error)
	}
	return nil
}

Create one producer per process and reuse it; call p.Flush(timeoutMs) and p.Close() on shutdown.

Kafka Consumer With Manual Commit

go
func Consume(brokers, group, topic string, handle func(*kafka.Message) error) error {
	c, err := kafka.NewConsumer(&kafka.ConfigMap{
		"bootstrap.servers":  brokers,
		"group.id":           group,
		"auto.offset.reset":  "earliest",
		"enable.auto.commit": false, // commit only after successful handling
	})
	if err != nil {
		return fmt.Errorf("create consumer for group %s: %w", group, err)
	}
	defer c.Close()
	if err := c.SubscribeTopics([]string{topic}, nil); err != nil {
		return fmt.Errorf("subscribe %s: %w", topic, err)
	}
	for {
		msg, err := c.ReadMessage(-1)
		if err != nil {
			if kerr, ok := err.(kafka.Error); ok && kerr.IsFatal() {
				return fmt.Errorf("fatal consumer error: %w", err)
			}
			continue // transient errors are retried by the client
		}
		if err := handle(msg); err != nil {
			// Hand off to retry/DLQ topic rather than blocking the partition forever.
			return fmt.Errorf("handle offset %v: %w", msg.TopicPartition, err)
		}
		if _, err := c.CommitMessage(msg); err != nil {
			return fmt.Errorf("commit offset %v: %w", msg.TopicPartition, err)
		}
	}
}

Idempotent Consumer

At-least-once means duplicates will arrive (rebalances, crashes before commit). Make the handler safe:

sql
CREATE TABLE processed_events (
  consumer   text        NOT NULL,
  event_id   text        NOT NULL,
  processed_at timestamptz NOT NULL DEFAULT now(),
  PRIMARY KEY (consumer, event_id)
);
-- In the same transaction as the side effect:
INSERT INTO processed_events (consumer, event_id) VALUES ('billing', $1)
ON CONFLICT DO NOTHING;   -- 0 rows affected => duplicate, skip side effect

Retries and Dead-Lettering

  • Kafka: on failure publish to orders.retry.1m, orders.retry.10m, then orders.dlq, committing the original offset. Blocking retries in place stall the whole partition.
  • RabbitMQ: basic.nack with requeue=false routes to the queue's dead-letter exchange (x-dead-letter-exchange); use TTL queues for delayed retry.
  • Classify errors: validation/poison messages go straight to DLQ; transient (timeouts) retry with exponential backoff and jitter.
  • Alert on DLQ depth and provide a replay tool.

Anti-Patterns

Anti-patternFix
Publishing before DB commit, or DB + broker dual writeTransactional outbox or CDC
Random/null keys when order mattersKey by aggregate ID
Auto-commit with slow handlersManual commit after processing
Events that are disguised RPC ("PleaseSendEmail" awaiting reply)Use a command queue or synchronous call
Breaking schema changes on an existing topicVersion the event type; dual-publish during migration
One giant "events" topic for everythingTopic per event type or bounded context

Checklist

  • Event catalogue with owners, schema versions and keys.
  • Producer: acks=all, idempotence on, publish via outbox.
  • Consumers idempotent; offsets committed after processing.
  • Retry topics/queues and DLQ with alerting and replay.
  • Consumer lag, DLQ depth and end-to-end latency monitored.
  • Trace context propagated in message headers.

References

  • Related skills: skills/backend/universal/event-driven/SKILL.md, skills/backend/universal/message-queue/SKILL.md, skills/backend/universal/transactional-outbox/SKILL.md, skills/backend/universal/event-sourcing/SKILL.md.

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

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

Use this skill when the user says 'event-driven architecture', 'EDA', 'publish domain events', 'kafka producer', 'kafka consumer', 'rabbitmq exchange', 'event broker', 'at-least-once delivery', 'event ordering', 'consumer group'. Designs broker-based event flows (Kafka or RabbitMQ): event shape, topic/exchange layout, partitioning for ordering, delivery guarantees, consumer idempotency, retries and dead-lettering, with working producer/consumer code. Do NOT use for: event sourcing as a persistence model (backend-event-sourcing), broker operations and tuning (backend-message-queue), reliable...

Vì sao nên dùng Backend Event Driven Architecture 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. Backend Event Driven Architecture 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 Backend Event Driven Architecture 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/backend/event-driven-architecture. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để 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 Backend Event Driven Architecture?

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 Backend Event Driven Architecture 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 Backend Event Driven Architecture 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 Backend Event Driven Architecture 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 👇