confluentinc / kafka-rest

Confluent REST Proxy for Kafka
https://docs.confluent.io/current/kafka-rest/docs/index.html
Other
46 stars 647 forks source link

Simplify load balancing of kafka-rest with haproxy #110

Open edoardocomar opened 9 years ago

edoardocomar commented 9 years ago

Given a cluster of kafka-rest servers, it would be desirable to allow haproxy to

At the moment, the simplest approach would be to have a cookie set by the load balancer. Perhaps thsi could become insteadt part of the kafka-rest API by having it set by the server and documented.

see also http://blog.haproxy.com/2012/03/29/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/

kjvalencik commented 9 years ago

Creating a consumer instance returns the hostname (base_uri) of the instance. Are your instances not individually and predictably addressable? You could set HAProxy to hash on source ip.

http://docs.confluent.io/1.0/kafka-rest/docs/api.html#post--consumers-(string-group_name)

edoardocomar commented 9 years ago

Hi Kjvalencik,

kjvalencik commented 9 years ago

That makes sense. The cookie thing would definitely work. A couple more options:

I've only done layer 3 proxying in HAProxy, but here would be the equivalent in nginx:

upstream kafka_rest_upstream {
    server 1.kafka-rest.local:8082;
    server 2.kafka-rest.local:8082;
    server 3.kafka-rest.local:8082;
}

server {
    server_name kafka-rest.local;
    listen 8082;

    location /(\d+)/ {
        proxy_pass http://$1.kafka-rest.local:8082/;
    }

    location / {
        proxy_pass http://kafka_rest_upstream;
    }
}

Subscribing would then return "base_uri" : "1.kafka-rest.local:8082" and you would re-write that as kafka-rest.local:8082/1/