Sobes.tech
Senior

Tell me about Kafka.

sobes.tech AI

Answer from AI

Apache Kafka is a distributed data streaming platform designed for processing large volumes of messages in real-time. It is used for building messaging systems, streaming analytics, and data integration.

Key features of Kafka:

  • Publish-Subscribe: producers send messages to topics, and consumers read them.
  • High performance: capable of processing millions of messages per second.
  • Scalability: easily scales horizontally.
  • Durability: stores data on disk with replication.

In Go, libraries such as segmentio/kafka-go or confluent-kafka-go are often used for working with Kafka.

Example of a simple producer in Go using kafka-go:

package main

import (
    "context"
    "log"
    "github.com/segmentio/kafka-go"
)

func main() {
    writer := kafka.NewWriter(kafka.WriterConfig{
        Brokers: []string{"localhost:9092"},
        Topic:   "example-topic",
    })
    defer writer.Close()

    err := writer.WriteMessages(context.Background(),
        kafka.Message{
            Key:   []byte("Key-A"),
            Value: []byte("Hello Kafka from Go!"),
        },
    )
    if err != nil {
        log.Fatal("failed to write messages:", err)
    }
}

Kafka is widely used for building microservice architectures, monitoring systems, and real-time event processing.

Tell me about Kafka. — Golang - sobes.tech