Redpanda isn’t just a Kafka clone; it’s a Kafka-compatible streaming platform built from scratch in C++ with a focus on operational simplicity and performance.
Let’s watch it in action. Imagine we have a simple producer sending messages to a Kafka topic named user_events.
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/segmentio/kafka-go"
)
func main() {
producer := &kafka.Writer{
Addr: kafka.TCP("localhost:9092"), // Default Kafka address
Topic: "user_events",
Balancer: &kafka.LeastBytes{},
}
defer producer.Close()
for i := 0; i < 10; i++ {
msg := kafka.Message{
Key: []byte(fmt.Sprintf("user_%d", i)),
Value: []byte(fmt.Sprintf("{\"event\": \"login\", \"user_id\": %d}", i)),
}
err := producer.WriteMessages(context.Background(), msg)
if err != nil {
log.Fatalf("Failed to send message: %v", err)
}
fmt.Printf("Sent message: %s\n", string(msg.Value))
time.Sleep(100 * time.Millisecond)
}
}
Now, we want to switch our consumer to point to Redpanda, which we’ll assume is running on localhost:9093. Redpanda is designed to be a drop-in replacement, so the same consumer code should work without modification, provided Redpanda is accessible at the new address.
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/segmentio/kafka-go"
)
func main() {
consumer := kafka.NewReader(kafka.ReaderConfig{
Brokers: []string{"localhost:9093"}, // Pointing to Redpanda
Topic: "user_events",
GroupID: "user_processor_group",
MinBytes: 10e3, // 10KB
MaxBytes: 10e6, // 10MB
})
defer consumer.Close()
fmt.Println("Consumer started, waiting for messages...")
for {
msg, err := consumer.ReadMessage(context.Background())
if err != nil {
log.Printf("Error reading message: %v", err)
continue
}
fmt.Printf("Received message: Topic=%s, Partition=%d, Offset=%d, Key=%s, Value=%s\n",
msg.Topic, msg.Partition, msg.Offset, string(msg.Key), string(msg.Value))
// Simulate processing
time.Sleep(50 * time.Millisecond)
}
}
The core problem Redpanda solves is the operational overhead associated with traditional Kafka. Kafka often requires separate ZooKeeper clusters for coordination, which adds complexity, latency, and operational burden. Redpanda integrates the coordination logic directly into the broker itself using the Raft consensus algorithm. This means you can run a single Redpanda node, or a cluster of Redpanda nodes, without managing ZooKeeper. This simplification extends to its API; it implements the Kafka protocol, so existing Kafka clients, tools, and connectors work out of the box. Performance is another key differentiator, with Redpanda designed for high throughput and low latency, often achieving better performance than Kafka on similar hardware due to its modern C++ implementation and efficient data handling.
The migration process itself is remarkably straightforward because of this compatibility. The primary steps involve:
- Setting up Redpanda: Install and configure Redpanda. For a simple test, a single
rpk container startcommand will suffice. For production, consider a multi-node cluster. - Creating Topics: Ensure the necessary topics exist in Redpanda. You can use
rpk topic create user_events. - Redirecting Clients: This is the crucial step. You’ll change your producer and consumer configurations to point to Redpanda’s broker address (e.g.,
localhost:9093or your cluster’s IP/DNS) instead of Kafka’s. - Testing: Run your applications against Redpanda.
The beauty is that if your applications are using standard Kafka client libraries (Java, Go, Python, Node.js, etc.), they should connect and operate with Redpanda as if it were Kafka. You don’t need to rewrite your application logic.
One of the most surprising aspects for newcomers is how Redpanda handles topic creation and partition management. While you can pre-create topics using rpk, Redpanda also supports automatic topic creation if enabled (which is the default). When a producer attempts to send a message to a non-existent topic, Redpanda can automatically create that topic with default settings. This behavior is similar to Kafka’s auto-topic creation, but Redpanda’s internal implementation, leveraging Raft for metadata management, makes this process more integrated and less prone to race conditions that could sometimes plague Kafka’s ZooKeeper-dependent auto-creation. This means you can often get started with minimal upfront configuration, letting the platform adapt as your data streams evolve.
The next step in your streaming journey will likely involve exploring Redpanda’s unique features beyond Kafka compatibility, such as its built-in schema registry and its HTTP API for data ingestion and querying.