Engineering — 1 min read

Event-driven systems with Kafka and NATS: Go and Node.js consumers

Engineering / Notes

Event-driven systems with Kafka and NATS: Go and Node.js consumers

Events are a contract between teams, not just a transport detail. I often have Go workers and Node.js services consuming the same stream, so the contract has to be runtime-neutral.

Start with the contract

Every event carries an ID, a type, a version and a timestamp. Consumers must tolerate unknown fields and deduplicate by ID:

{"id":"evt_123","type":"ride.completed","version":1,"occurred_at":"2026-04-02T10:00:00Z"}

A Go consumer

for msg := range messages {
    var event Event
    if err := json.Unmarshal(msg.Data, &event); err != nil {
        continue // dead-letter it
    }
    if seen.Mark(event.ID) { msg.Ack(); continue }
    if err := handle(ctx, event); err != nil { continue }
    msg.Ack()
}

The same consumer in Node.js

await consumer.run({
  eachMessage: async ({ message }) => {
    const event = JSON.parse(message.value.toString())
    if (await seen.mark(event.id)) return
    await handle(event)
  },
})

Notice that the logic is identical. The runtimes differ in how they schedule work, not in what correct handling means.

Kafka or NATS?

Kafka gives you a durable, replayable log and consumer groups. NATS (with JetStream when you need persistence) is lighter and faster for service-to-service fan-out. Many systems use both: Kafka as the record of truth, NATS for low-latency internal events.

Backpressure

In Go, bound your worker pool with a channel. In Node.js, limit concurrency explicitly with a queue — Promise.all over an unbounded list is a great way to exhaust memory.

Key takeaways

Design the event first, make consumers idempotent, then pick the transport. The runtime should not change the semantics.

RA
Written by

Rustambek Abdusalomov

Senior Software Engineer based in Tashkent. Distributed systems, Go and infrastructure that stays up.

Discussion

Comments (0)

Approved comments appear after moderation

No comments yet

Be the first to start the conversation.

Join the discussion

Comments are moderated before they appear.