agentsclimarketplace

Multi tenant kafka header organization context

Skill kjuhwa/skills-hub/skills/backend/multi-tenant-kafka-header-organization-context

Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.

Install
npx -y skills add kjuhwa/skills-hub --skill multi-tenant-kafka-header-organization-context

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Propagate tenant/organization id from Kafka headers through async handler threads via a ThreadLocal context holder

SKILL.md

1.9 KB, as published. Nobody here has run it

Multi-tenant Kafka header → context propagation

Keep tenant id out of message payloads when possible; carry it in a Kafka header so routing can happen without deserializing the body. On the consumer side, extract once and push into a TenantContextHolder ThreadLocal before dispatching to async handlers.

Shape

  • Producer sets header organizationId (or tenantId) on every record.
  • Consumer reads header, wraps payload + header into an event wrapper (e.g. CollectionEvent(organizationId, payload)).
  • Before handing to an executor/BlockingQueue consumer, set TenantContextHolder.set(orgId); always clear in finally.
  • Handler threads must inherit the context — use DelegatingSecurityContextExecutor-style wrapping or set inside the runnable, NOT by relying on InheritableThreadLocal across a long-lived pool.

Steps

  1. Define TenantContextHolder with set/get/clear over a plain ThreadLocal<String>.
  2. In the Kafka listener: read organizationId from headers; reject records missing it.
  3. Wrap payload in an event object that carries organizationId explicitly (don't depend on ThreadLocal across queue boundaries).
  4. On the consuming thread (handler), first line: TenantContextHolder.set(event.orgId); try { handle(event); } finally { TenantContextHolder.clear(); }.
  5. Any downstream code reaching into tenant-scoped stores reads from the holder.
  6. Guardrail: queue-based hand-offs cross threads — never rely on ThreadLocal surviving the hand-off; always re-set on the other side.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.