惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
J
Java Code Geeks
U
Unit 42
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
D
Docker
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
I
InfoQ
The Cloudflare Blog
小众软件
小众软件
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
P
Proofpoint News Feed
V
V2EX
月光博客
月光博客
Martin Fowler
Martin Fowler

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I built a transactional outbox toolkit for Node.js — meet...
Samet GOKTEPE · 2026-06-17 · via DEV Community

Samet GOKTEPE

If your Node.js service writes to Postgres and publishes events to Kafka or Redpanda, you probably have a silent dual-write bug. I built eventferry to fix it: write your event in the same transaction as your data, and a background relay reliably ships it to the broker. MIT-licensed, zero dep core,

## The bug you might not know you have

You write the order to your database. You commit. You send to Kafka.

  await db.query("INSERT INTO orders ...");
  await kafka.send({ topic: "orders.created", ... });

Looks fine. Until a crash or a Kafka outage hits between those two calls. The DB thinks the order happened; downstream services never hear about it. Quietly broken — until production breaks.

This is the dual-write problem, and it's the reason event-driven Node.js services fail in ways that are very hard to debug after the fact.

## The fix is the transactional outbox pattern

Write the event into an outbox table in the same transaction as your business data. A background relay picks rows off that table and reliably publishes them to the broker.

  ┌─────────────┐   one TX     ┌──────────────┐   relay     ┌───────────────┐
  │  your code  │ ───────────▶ │  outbox tbl  │ ──────────▶ │ Kafka/Redpanda│
  │ (order svc) │   (atomic)   │  (Postgres)  │   publish   │     topic     │
  └─────────────┘              └──────────────┘             └───────────────┘

It's a well-known pattern, but most Node.js implementations get the corners wrong: strict per-aggregate ordering under concurrent relays, the crash-recovery reaper, retry/backoff math, DLQ routing, Schema Registry serialization.

## Why a new library — the honest answer

There are three answers when you Google this:

  • Debezium is the obvious one. Great, but it's a JVM cluster + Kafka Connect to operate, and events are row-level (not domain-level). For a Node.js team that just wants a library, that's heavy.
  • pg-boss / BullMQ keep getting suggested for this — they're job queues, not outboxes. There's no atomic dual-write with your business transaction.
  • A DIY outbox table is what most teams roll. It works until it doesn't; the parts that bite you are exactly the ones you haven't written yet — per-aggregate ordering, the reaper, retry/backoff, DLQ.

eventferry is the "I just want a small library" option.

## Quick start

  import { Relay, PostgresStore, KafkaPublisher } from "@eventferry/all";

  const store = new PostgresStore({ pool });
  const publisher = new KafkaPublisher({
    driver: "kafkajs",
    brokers: ["localhost:19092"],
    idempotent: true,
  });

  // Inside your business transaction:
  await store.enqueue(client, {
    topic: "orders.created",
    aggregateType: "order",
    aggregateId: order.id,
    payload: { orderId: order.id, total: order.total },                                                                                                                                                                                                                                                           
  });

  // Background relay:
  const relay = new Relay({ store, publisher, dlq: { topic: "orders.dlq" } });
  await relay.start();
  process.on("SIGTERM", () => relay.stop());

That's the whole pattern.

## What's inside

  • Strict per-aggregate ordering across N concurrent relays (FOR UPDATE SKIP LOCKED + a NOT EXISTS guard)
  • 🔄 Crash-recovery reaper — visibility timeout reclaims rows stuck in processing
  • 🔁 Retries with backoff + jitter, DLQ routing for terminal failures
  • Low-latency delivery: poll, LISTEN/NOTIFY waker, or WAL streaming relay (same mechanism Debezium uses)
  • 🔒 Type-safe event registry with Standard Schema validation
  • 📦 Schema Registry support (Avro / Protobuf / JSON Schema, Confluent wire format)
  • 🧭 W3C trace propagation (OpenTelemetry-ready)
  • 🪶 Zero-dependency core; pluggable store and broker

Integration tests run against real Postgres + Redpanda via Testcontainers.

## Roadmap

PostgreSQL ships today. MySQL/MariaDB, SQL Server, and MongoDB are next — the relay is database-agnostic; each adapter is the OutboxStore contract. CockroachDB, SQLite, Oracle, and DynamoDB are on the horizon. Full plan with architecture diagrams: ROADMAP.md.

## Try it

  npm i @eventferry/all pg kafkajs

If you've tried Debezium or pg-boss or a DIY outbox for this and either landed somewhere good or got bitten, I'd love to hear about it in the comments.