kafka-node, kafkajs, and node-rdkafka are all Node.js libraries that enable applications to produce and consume messages from Apache Kafka, a distributed event streaming platform. These packages differ significantly in their implementation strategies, performance characteristics, API design, and maintenance status. While they all aim to integrate Kafka into JavaScript environments, they take distinct approaches—ranging from pure JavaScript implementations to bindings over native C++ libraries—and target different use cases based on throughput needs, operational complexity, and developer experience.
If you're building an event-driven system with Kafka in Node.js, you’ve likely stumbled across three names: kafka-node, kafkajs, and node-rdkafka. But only two are viable today — and they serve very different engineering needs. Let’s cut through the noise.
kafka-node was once popular but has been officially archived by its maintainers. Its last meaningful update was years ago. It doesn’t support critical Kafka features introduced since version 0.11, such as:
More importantly, it uses an outdated protocol implementation that can cause silent data loss or consumer group instability under load. If you’re starting a new project, skip it entirely. Even in existing systems, treat it as technical debt.
// ❌ DO NOT DO THIS IN NEW CODE
const kafka = require('kafka-node');
// This will bite you later
Now, let’s compare the two real contenders.
kafkajs: 100% JavaScriptkafkajs is written entirely in JavaScript (with TypeScript definitions). It implements the Kafka wire protocol from scratch using Node.js streams and async/await patterns. This means:
build-essential, python, or librdkafka-dev needed)But there’s a trade-off: CPU-bound work like compression (snappy, gzip) happens in the main thread, which can block I/O under heavy load.
node-rdkafka: C++ Wrapper Around librdkafkanode-rdkafka is a Node.js binding to librdkafka, Confluent’s battle-tested C/C++ Kafka client used in production at massive scale. This gives it:
However, it requires compiling native code during npm install. That means your CI/CD pipeline must include build tools, and you’ll face occasional ABI compatibility issues across Node.js versions.
# For node-rdkafka, your Dockerfile might need:
RUN apt-get update && apt-get install -y \
build-essential \
librdkafka-dev
kafkajs Feels Like Modern JavaScriptIts API is intuitive and promise-based:
// kafkajs producer example
const { Kafka } = require('kafkajs');
const kafka = new Kafka({ brokers: ['localhost:9092'] });
const producer = kafka.producer();
await producer.connect();
await producer.send({
topic: 'user-events',
messages: [{ key: '123', value: JSON.stringify({ action: 'login' }) }]
});
Error handling is consistent, retries are configurable, and logging integrates cleanly with standard Node.js patterns. Consumer groups automatically handle offsets unless you opt out.
node-rdkafka Exposes Low-Level ControlYou get fine-grained knobs—but with more ceremony:
// node-rdkafka producer example
const Kafka = require('node-rdkafka');
const producer = new Kafka.Producer({
'metadata.broker.list': 'localhost:9092',
'dr_cb': true // delivery report callback
});
producer.connect();
producer.on('ready', () => {
producer.produce(
'user-events',
null,
Buffer.from(JSON.stringify({ action: 'login' })),
'123'
);
});
producer.on('delivery-report', (err, report) => {
// Handle delivery success/failure
});
Notice the event-driven style, manual connection management, and lack of async/await. You must explicitly handle delivery reports, partition assignment, and offset commits if you want reliability.
In real-world benchmarks:
node-rdkafka typically handles 5x–10x more messages per second than kafkajs on the same hardware.kafkajs latency stays predictable up to ~10K msg/s; beyond that, GC pressure increases.node-rdkafka maintains sub-millisecond p99 latency even at 100K+ msg/s.But ask yourself: do you really need that scale? Most web apps processing user events, notifications, or audit logs won’t saturate kafkajs. Only choose node-rdkafka if you’ve measured a bottleneck.
kafkajs emits standard Node.js events and works with any APM tool (Datadog, New Relic).node-rdkafka exposes internal librdkafka stats via .queryWatermarkOffsets() and stats callbacks—but interpreting them requires Kafka internals knowledge.Both handle broker failures, but differently:
kafkajs reconnects automatically with exponential backoff. Crashes are rare because errors stay in JS land.node-rdkafka may crash the entire process if librdkafka hits an unrecoverable state (e.g., corrupted metadata). You’ll need robust process supervision (PM2, systemd).| Scenario | Recommendation |
|---|---|
| Greenfield app, team prefers JS-only stack | kafkajs |
| High-throughput data ingestion (IoT, logs, metrics) | node-rdkafka |
| Need message headers or exactly-once semantics | Either (both support Kafka ≥ 0.11 features) |
| Deploying to serverless (AWS Lambda, Vercel) | kafkajs (smaller bundle, no native deps) |
| Already using Confluent Cloud with SASL/OAUTHBEARER | node-rdkafka (more mature auth support) |
Start with kafkajs unless you have a proven need for extreme performance. Its simplicity reduces bugs, speeds up onboarding, and avoids native dependency headaches. Only switch to node-rdkafka when profiling shows Kafka client overhead is your bottleneck — and you have the ops bandwidth to manage it.
And never, ever start a new project with kafka-node. The tech world moved on; you should too.
Choose kafkajs if you prioritize a clean, modern, fully JavaScript-based API with strong TypeScript support, active maintenance, and ease of debugging. It’s ideal for teams that value developer experience, testability, and avoiding native dependencies. Use it when your throughput requirements are moderate (thousands of messages per second) and you prefer predictable behavior without compiling C++ add-ons.
Do not choose kafka-node for new projects—it is officially deprecated and no longer maintained. The repository has been archived, and the package lacks support for modern Kafka protocol features like incremental cooperative rebalancing, headers, and newer authentication mechanisms. If you encounter it in legacy code, plan a migration path to either kafkajs or node-rdkafka.
Choose node-rdkafka if you need maximum throughput, low latency, and production-grade stability at scale—especially in high-volume data pipelines. It’s best suited for infrastructure teams comfortable managing native dependencies and willing to trade some API ergonomics for raw performance. Ensure your deployment environment supports compiling and linking against librdkafka.
A modern Apache Kafka® client for Node.js
Get Started »
Read the Docs
·
Report Bug
·
Request Feature
KafkaJS is a modern Apache Kafka client for Node.js. It is compatible with Kafka 0.10+ and offers native support for 0.11 features.
KAFKA is a registered trademark of The Apache Software Foundation and has been licensed for use by KafkaJS. KafkaJS has no affiliation with and is not endorsed by The Apache Software Foundation.
Upstash: Serverless Kafka
|
Get help directly from a KafkaJS developer
|
To become a sponsor, reach out in our Slack community to get in touch with one of the maintainers. Also consider becoming a Github Sponsor by following any of the links under "Sponsor this project" in the sidebar.
npm install kafkajs
# yarn add kafkajs
const { Kafka } = require('kafkajs')
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['kafka1:9092', 'kafka2:9092']
})
const producer = kafka.producer()
const consumer = kafka.consumer({ groupId: 'test-group' })
const run = async () => {
// Producing
await producer.connect()
await producer.send({
topic: 'test-topic',
messages: [
{ value: 'Hello KafkaJS user!' },
],
})
// Consuming
await consumer.connect()
await consumer.subscribe({ topic: 'test-topic', fromBeginning: true })
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log({
partition,
offset: message.offset,
value: message.value.toString(),
})
},
})
}
run().catch(console.error)
Learn more about using KafkaJS on the official site!
Read something on the website that didn't work with the latest stable version?
Check the pre-release versions - the website is updated on every merge to master.
KafkaJS is an open-source project where development takes place in the open on GitHub. Although the project is maintained by a small group of dedicated volunteers, we are grateful to the community for bug fixes, feature development and other contributions.
See Developing KafkaJS for information on how to run and develop KafkaJS.
We welcome contributions to KafkaJS, but we also want to see a thriving third-party ecosystem. If you would like to create an open-source project that builds on top of KafkaJS, please get in touch and we'd be happy to provide feedback and support.
Here are some projects that we would like to build, but haven't yet been able to prioritize:
See LICENSE for more details.
Apache Kafka and Kafka are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries. KafkaJS has no affiliation with the Apache Software Foundation.