stack-kafka
Skill0 starsChanged 5 months agoApache-2.0View on GitHub
Apache Kafka messaging patterns for agents working in projects whose docs/TECH_STACK.md lists kafka. Load when implementing, testing, or reviewing event-driven code on Kafka.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Snakeblack/ospec-workflowtheir own version, first seen Nov 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Snakeblack/ospec-workflow★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository17 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- flow-adoptionSkill
- flow-legacy-migrationSkill
- stack-awsSkill
- stack-azureSkill
- stack-design-systemSkill
- stack-gcpSkill
- stack-javaSkill
- stack-mongodbSkill
- stack-natsSkill
- stack-nestjsSkill
- stack-nextjs-reactSkill
- stack-nxSkill
- stack-playwrightSkill
- stack-postgresqlSkill
- stack-quarkusSkill
- stack-react-nativeSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 106
All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stack: Kafka
Kafka is a broker option behind the messaging port of .claude/docs/DEFAULT_TARGET_ARCHITECTURE.md §4 (NATS/JetStream is the default; Kafka is a per-project or premise choice) — always ONE adapter behind a messaging port, never a direct module dependency. Where the host's docs/ARCHITECTURE.md declares different conventions, the host docs win. Kafka is a partitioned, ordered, replayable log, not a queue — most of the discipline below follows from that one fact.
When this applies
Detection markers (any of):
docs/TECH_STACK.md## Detected stackslistskafka- Dependencies (Node):
kafkajs,@nestjs/microservicesconfigured with the Kafka transport. (JVM):org.apache.kafka:kafka-clients,quarkus-messaging-kafka/smallrye-reactive-messaging-kafka, Spring Kafka - Config:
bootstrap.servers/kafka.bootstrap.servers,mp.messaging.*Kafka connector keys, a schema-registry URL - Files: a
kafka/redpandaservice indocker-compose.yml; committed topic definitions or Avro/Protobuf schemas + registry config
Implementation patterns
THE PORT RULE (non-negotiable)
Modules depend on a messaging port — an abstract contract owned by the module's PURE core (domain/ on NestJS, application/ on Quarkus — per the backend stack skill). The Kafka producer/consumer is one implementation:
// PURE core (domain/ on NestJS, application/ on Quarkus)
export abstract class EventBus {
abstract publish(event: DomainEvent): Promise<void>
}
// adapter layer (adapters/ on NestJS, infrastructure/ on Quarkus); the Kafka client (KafkaJS / kafka-clients) lives ONLY here
export class KafkaEventBus extends EventBus { /* ... */ }- Domain/application code NEVER imports a Kafka client. A
kafkajs/org.apache.kafkaimport outside the adapter directory is a review BLOCKER. On the JVM this is the port interface +@ApplicationScopedadapter pattern from.claude/skills/stack-quarkus/SKILL.md(R-ARCH-07). - Swapping brokers (premise "NATS instead of Kafka", or "SNS/SQS") binds a different adapter at the SAME port — adapters change, modules don't.
Topic taxonomy & schema
- Topic names are past-tense facts (R-ARCH-09):
<domain>.<entity>.<event>→billing.invoice.created. Never imperative (billing.invoice.createis RPC in disguise). - Schema registry is the contract. Avro/Protobuf/JSON-Schema registered with a compatibility mode (BACKWARD by default). Evolve compatibly (add optional fields); a breaking change is a NEW topic or an explicit version suffix — never mutate a schema in place. Producers and consumers both derive from the registered schema, not from each other.
- Multi-tenant: tenant id in the key or a header — NEVER payload-only. Key/header placement lets partitioning, ACLs, and per-tenant filtering work without deserializing every record.
Partitioning & keys (the Kafka-specific invariant)
- Ordering is per-partition only — there is NO global order. The record KEY hashes to a partition; all records with the same key are ordered relative to each other. Choose the key as the entity whose ordering the domain requires (typically the aggregate id:
invoice.id). - A spec that needs per-aggregate ordering and leaves the key null (round-robin) is a BLOCKER — events for one aggregate scatter across partitions and reorder.
- Changing partition count rehashes key→partition and breaks ordering for in-flight keys. Treat partition count as a capacity decision made up front; document it. Beware hot-key skew (one tenant/aggregate saturating one partition).
Consumer groups, offsets & rebalance
- One consumer group per consuming module — the group is the scaling/competing-consumer unit; partitions are distributed across its members. Two modules that both need the events use two groups (each gets every record).
- Commit the offset AFTER side effects are durably committed, with manual commit — auto-commit (or commit-then-process) acknowledges records you may crash before handling, losing them. Process → persist → commit.
- Rebalances cause reprocessing: a partition reassigned mid-batch redelivers uncommitted records to another member. Idempotency (below) is what makes that safe — there is no avoiding redelivery.
Delivery semantics & idempotency (mandatory)
- At-least-once is the default contract → every consumer dedupes by
(topic, partition, offset)or a persisted business id (R-ARCH-11). A duplicate maps to a typed replay no-op, never an error. - Exactly-once (EOS) — idempotent producer (
enable.idempotence=true) + transactions (transactional.id) +read_committedconsumers — applies ONLY to Kafka→Kafka flows (consume-transform-produce). It does not extend to external side effects (DB writes, HTTP): a handler that writes a row still needs idempotency or an outbox. Don't claim EOS for a chain that touches anything non-transactional with Kafka.
Dead-letter & retry topics
- Every consumer declares a retry/DLT strategy: bounded retries (in-place or via a retry topic), then route the poison record to a dead-letter topic with the failure context in headers. A consumer with no DLT path either blocks the partition (head-of-line blocking — one poison record stalls everything behind it) or silently drops it. Both are defects.
Outbox for DB-write + publish atomicity
Never publish inside an uncommitted transaction without an outbox. In-transaction publish announces state that may roll back; naive post-commit publish is lost if the process dies between commit and produce. When the spec needs the event reliably:
TX: [ write domain rows + insert outbox row ] → COMMIT
relay: poll/tail outbox (or Debezium CDC) → produce (key = aggregate id, dedupe id = outbox row id) → mark sentThe outbox row id doubles as the dedupe id, making the relay safely retryable. Plain post-commit fire-and-forget is acceptable ONLY for events the spec marks lossy-tolerant (telemetry, advisory).
Kafka is not request-reply
Kafka is a durable log for facts and fan-out — producers don't know consumers. A "consumer" that exists solely to run a command for one producer, or a reply-topic correlation dance to get a synchronous answer, is RPC in disguise. Use a direct module-public call (or core NATS request-reply if the project also runs NATS) instead of faking it over the log.
Testing on this stack
- Integration: real Kafka via Testcontainers (
confluentinc/cp-kafkaorredpandadata/redpanda) or the composekafkaservice — never a mocked client (R-TESTI-01 spirit: mocks stay green while topic/partition/serde config is wrong). Use the schema registry the project uses; validate serialization against it. - Contract tests on topic + key + headers + schema: the producer test asserts what actually landed (key, headers, registry-valid payload); the consumer test feeds the declared shape and asserts the side effect. Both sides test against the declared contract, not against each other.
- Double-delivery idempotency assertion (mandatory): deliver the same record twice (same key/offset or business id), assert EXACTLY one side effect (R-TESTI-02 adapted).
- Ordering/partition test: records sharing a key land on one partition and preserve order; a different key may interleave. Cover the rebalance path — restart a consumer mid-stream, assert no lost or double-applied side effect beyond idempotency.
- Tests own their topics: unique topic names and consumer-group ids per suite (or delete in teardown) so parallel suites never share offsets.
Spec validation checks
Stack-specific checks the spec validators (spec-validate-lead-engineer, on SPEC_<FEATURE>.md §4–6) delegate here:
| Check | Severity |
| Event consumer without a declared idempotency strategy (offset or business-id dedupe) | BLOCKER |
| Per-aggregate ordering required but no partition key carries it (null/round-robin key) | BLOCKER |
| Offsets committed before side effects are durably committed (commit-then-process / auto-commit) | BLOCKER |
| Publish inside an uncommitted DB transaction without an outbox | BLOCKER |
| Module producing/consuming around the messaging port (Kafka client import outside the adapter) | BLOCKER |
| Consumer without a dead-letter / bounded-retry strategy (head-of-line blocking risk) | WARNING |
| Schema evolved incompatibly, or no registry compatibility mode declared | WARNING |
| Exactly-once claimed for a chain that includes external (non-Kafka) side effects | WARNING |
| Tenant id carried payload-only (not in key or headers) | WARNING |
Live validation commands
R-VAL-01 obligations for messaging changes — exact invocations live in docs/DEV_SETUP.md; the rows below are the obligations:
| Check | Typical shape |
| Broker up in compose | docker compose up -d kafka (or redpanda) per DEV_SETUP |
| Topics created as declared | kafka-topics --list / rpk topic list against the local broker |
| Schema registered with the expected compatibility | registry CLI/HTTP check per DEV_SETUP |
| Run affected integration tests (real Kafka) | test target per DEV_SETUP |
| Double-deliver smoke for touched consumers | produce the same keyed record twice (kafka-console-producer / rpk topic produce); observe exactly one side effect |
All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

