Kafka
ELB
Broker Cluster
Kafka Support
Distributed Systems

Does Kafka support ELB in front of broker cluster?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Apache Kafka, developed by the Apache Software Foundation, is a distributed event streaming platform capable of handling trillions of events a day. Oftentimes, Kafka is deployed in production environments where high availability and scalability are critical requirements. To achieve these, the applicability of load balancers, like Elastic Load Balancing (ELB) from AWS, becomes a topic of consideration. However, involves understanding how Kafka interacts with clients and other system components.

Understanding Kafka Brokers and Clients

Kafka operates on a cluster of brokers where each broker is a server that stores data and serves client requests. Clients can produce (write) or consume (read) data by connecting to these brokers. Kafka maintains a list of brokers and their metadata, which is shared with clients. This metadata includes information about which broker is holding which partitions of a topic.

Why Standard Load Balancers are Less Ideal

Typical load balancers like AWS's ELB are designed to distribute incoming network traffic across multiple downstream targets. This can be useful in scenarios where stateless web applications are hosted across multiple servers. However, Kafka's client-broker communication does not fit well with this model for several reasons:

  1. Persistent Connections: Kafka clients establish long-lived connections to brokers to consume or produce messages continuously. Load balancers designed for HTTP traffic typically expect short-lived connections.
  2. Intelligent Client: Kafka clients are aware of the cluster's topology. They directly interact with the broker that holds the data they need to read from or write to. This is managed through periodic metadata updates that clients retrieve directly from the brokers.
  3. Routing and Scalability: In Kafka, each partition of a topic can only be consumed by a single consumer in a group at a time which is managed by Kafka itself. Brokers also dynamically handle partitions and rebalancing. Putting a load balancer between clients and brokers could obscure visibility into the cluster state from a client’s perspective.

Where Load Balancers Could Fit

While traditional load balancing is not typically used directly in front of Kafka brokers for client traffic, there is still a role for load balancers in a Kafka ecosystem:

  • Admin Operations: Load balancers can be useful for managing connections and distributing load for administrative operations targeting Kafka’s REST Proxy or Control Center, if these components are deployed.
  • Inter-broker communication: In cloud environments, specifically in configurations where brokers are spread across different availability zones, internal load balancers might assist with managing and simplifying network traffic between brokers themselves.

Potential Use Cases for ELB with Kafka

If there is a decided advantage to integrating ELB in the Kafka setup, it would likely be in scenarios not directly involving core message passing. For instance:

  • Bootstrap and Failover: Although not commonly recommended, using ELB for the initial connection point to handle broker failures could be possible. Here, ELB could redirect connection requests to a healthy broker on broker failures.
  • Edge Case Load Balancing: For distributing indirect traffic or non-client-to-broker communications in multiple broker setups or across datacenters.

Summary Table

FeatureDirect Client-Broker InteractionELB Usage
Connection PersistenceRequiredNot ideal
Knowledge of Cluster StateEssentialObstructive
Protocol SupportTCP and custom protocolsPrimarily HTTP/HTTPS
Scalability and RebalancingManaged by clientsNA

Final Thoughts

Deploying Kafka with a traditional load balancer like ELB directly interfacing client and broker traffic goes against Kafka's architecture and operational dynamics. However, exploring specialized configurations for non-traditional use cases or administrative interfaces might offer limited scopes where ELB can be effectively integrated. Always consider Kafka's natural behavior and client requirements when evaluating its infrastructure setup.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.