Distributed Systems•Production Architecture Blueprint

Apache Kafka Distributed Event Streaming Architecture

Apache KafkaConfluent Schema RegistryAvroGoDocker
Architectural Definition

Apache Kafka distributed event streaming serves as the enterprise central nervous system, decoupling asynchronous microservices through high-throughput, fault-tolerant append-only log streams.

System Architecture & Core Mechanics

Messages are partitioned across broker clusters to allow horizontal consumer group scaling. The Transactional Outbox pattern guarantees that database state updates and published Kafka events execute atomically with zero message loss.

Recommended For
  • ✓High-volume event pipelines processing 10,000+ events per second
  • ✓Event-sourcing, financial audit ledgers, and distributed state replication
Avoid When
  • ✕Simple request-response CRUD operations or low-volume task dispatching

Trade-Off Analysis & Alternative Comparisons

DimensionApache Kafka Log StreamTraditional Message Broker (RabbitMQ)
Message StorageDurable, persistent log retained for days/monthsEphemeral queue deleted upon consumer ACK
ReplayabilityConsumers can rewind offsets to replay past eventsCannot replay consumed messages without re-queuing
Throughput CapacityMillions of events/sec via disk sequential writesTens of thousands of events/sec before memory saturation

Implementation Blueprint & Code Contracts

1

Step 1: Transactional Outbox Schema Pattern

Ensure atomic consistency between PostgreSQL entity updates and Kafka publishing via outbox table.

sql
CREATE TABLE outbox_events (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    aggregate_type VARCHAR(64) NOT NULL,
    aggregate_id VARCHAR(64) NOT NULL,
    payload JSONB NOT NULL,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    processed BOOLEAN DEFAULT FALSE
);

-- Mutation and outbox insertion in one atomic SQL transaction
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 'acc-123';
INSERT INTO outbox_events (aggregate_type, aggregate_id, payload) 
VALUES ('Account', 'acc-123', '{"event": "debited", "amount": 100}');
COMMIT;
2

Step 2: Idempotent Producer Configuration in Go

Configure producer with acks=all and exact duplicate filtering enabled at the broker level.

go
config := sarama.NewConfig()
config.Producer.RequiredAcks = sarama.WaitForAll // acks=all
config.Producer.Idempotent = true
config.Net.MaxOpenRequests = 1 // Required for strict order preservation
config.Producer.Return.Successes = true

producer, err := sarama.NewSyncProducer([]string{"kafka-broker:9092"}, config)
3

Step 3: Consumer Group with Dead Letter Queue (DLQ) Fallback

Isolate poison-pill messages after 3 retries into a DLQ topic without blocking the partition consumer offset.

go
func (h *ConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
    for msg := range claim.Messages() {
        if err := processMessage(msg.Value); err != nil {
            h.routeToDLQ(msg, err) // Route poison pill to error topic
        }
        sess.MarkMessage(msg, "") // Commit offset so pipeline continues
    }
    return nil
}
Associated Core Pillar

Custom Software

Connect with AEITCH architects to evaluate how this architecture pattern applies to your technical requirements.

Explore Custom Software