<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dushyant Dixit on Medium]]></title>
        <description><![CDATA[Stories by Dushyant Dixit on Medium]]></description>
        <link>https://medium.com/@dhd.dixit?source=rss-ceafd1757d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*R3JuAszypNWZrUvD3n4Mjw.jpeg</url>
            <title>Stories by Dushyant Dixit on Medium</title>
            <link>https://medium.com/@dhd.dixit?source=rss-ceafd1757d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:27:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhd.dixit/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Smart sticky sessions using HAProxy for Apache Phoenix]]></title>
            <link>https://medium.com/helpshift-engineering/smart-sticky-sessions-using-haproxy-for-apache-phoenix-911bdca7e2c?source=rss-ceafd1757d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/911bdca7e2c</guid>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[apache-phoenix]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[sysadmin]]></category>
            <dc:creator><![CDATA[Dushyant Dixit]]></dc:creator>
            <pubDate>Tue, 20 Aug 2019 11:26:13 GMT</pubDate>
            <atom:updated>2019-08-21T07:49:25.807Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>At Helpshift, our production engineering team is dedicated to ensuring the uptime and scalability of our cloud infrastructure. We extensively use <a href="http://www.haproxy.org/">HAProxy</a> to load balance and scale our TCP and HTTP-based applications.</p><p>In this post, we look at how we have used HAProxy to achieve load balancing for Apache Phoenix Query Server with sticky sessions.</p><h3>Apache Phoenix and what is it used for?</h3><p><a href="https://phoenix.apache.org/"><strong><em>Apache Phoenix</em></strong> </a>enables OLTP and operational analytics in Hadoop for low latency applications. It brings the power of standard SQL and JDBC APIs into HBase.</p><p>We use Apache Phoenix to power our Analytics APIs. Customers can derive their own product usage insights using this API. These APIs are synchronous and expected to have low latencies. Phoenix helps us run aggregated SQL queries on our massive data sets of tens of millions of rows with a latency of just a few seconds.</p><p>To know more about how we engineered our analytics API, you can read <a href="https://medium.com/helpshift-engineering/engineering-analytics-api-with-hbase-phoenix-and-sql-at-helpshift-980126f328a9">here</a>.</p><p>Before we define the problem statement, let me first introduce you to the Analytics API architecture at Helpshift.</p><p>Following are the components involved:</p><ul><li><strong>HBase </strong>is a column-oriented NoSQL database. We use it to store our Analytics data.</li><li><strong>Phoenix</strong> is used to provide standard SQL and JDBC APIs on top of HBase. It is designed for low latency OLTP workloads.</li><li><a href="https://phoenix.apache.org/server.html"><strong>Phoenix Query Server</strong></a><strong> (PQS)<em> </em></strong>provides an alternative means of interaction with Phoenix and HBase. It is responsible for managing <strong>Phoenix Connections on behalf of clients.</strong></li><li><strong>HAProxy </strong>for load balancing phoenix query servers.</li><li><strong>API service</strong> to expose this data to our customers over predefined documented schemas. This utilizes the SQL interface over PQS.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*UwLVZVPplUUO70WQ_Ldosw.png" /><figcaption>Analytics API Architecture at Helpshift</figcaption></figure><p>As you can see in the above figure, the API service makes JDBC requests (SQL query) over HTTP to PQS. PQS then transforms and optimizes these queries to HBase Scans, aggregates results, and returns it to the API service.</p><h3>Problem statement</h3><p>PQS requires clients (in our case, API service) to have a sticky session with it. This will ensure that clients do not spend an excessive amount of time in recreating the server-side state on PQS.</p><p>The <a href="https://phoenix.apache.org/server.html">PQS documentation</a> mentions:</p><blockquote>The Query Server can use off-the-shelf HTTP load balancers such as the <a href="https://httpd.apache.org/">Apache HTTP Server</a>, <a href="https://nginx.org/">nginx</a>, or <a href="https://haproxy.org/">HAProxy</a>. The primary requirement of using these load balancers is that the implementation must implement “sticky session” (when a client communicates with a backend server, that client continues to talk to that backend server).</blockquote><p>A standard solution to this problem is an architecture like the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*8fnDWloxbSWIfhR_MP0u9Q.png" /><figcaption>Solution using HAProxy stick tables</figcaption></figure><p>HAProxy can share <a href="https://www.haproxy.com/blog/introduction-to-haproxy-stick-tables/">stick tables</a> among multiple nodes with “peers” feature. In this method, HAProxy stick tables help us maintain stickiness based on the given request pattern, eg. source IP, HTTP header, etc.</p><p>We started testing our setup with the approach mentioned above. While testing for fault tolerance, we realized that this stick table solution comes with the following caveat.</p><p>If any of the PQS backends go down, the traffic gets redistributed on the available backend servers. But, when the node comes back up, the redistribution of the existing traffic doesn’t happen. Only the traffic from new client connections will get distributed. This makes load distribution imbalanced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*GFuMAG2CoL-t-xxB13okcA.png" /><figcaption>The issue with stick table solution</figcaption></figure><p>To overcome the problem mentioned above, stick table entries have to be purged manually, which might result in application errors (due to server-side state on PQS) as the connections are redistributed.</p><h3>Our Solution:</h3><p>To address the problems outlined above, we decided to get rid of existing HAProxy stick table solution. We set up a local HAProxy on all API service client nodes and route request through the local HAProxy. Using <strong>HDR</strong> load balancing algorithm in HAProxy, we ensure that stickiness is maintained per HTTP keepalive connection<strong>.</strong></p><p>API clients make connections to PQS through HAProxy, running locally on API server. This avoids the caveat mentioned in the stick table method above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*bvqU63eGCRNPShTCS_8K5g.png" /><figcaption>Our solution using HAProxy’s HDR routing algorithm</figcaption></figure><h4>What is HDR and how does it work?</h4><p>We have used HDR routing algorithm to achieve stickiness on a TCP connection level. This algorithm selects a backend server based on the HTTP header in each request.</p><p>From <a href="https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-balance">HAProxy documentation</a>:</p><pre><strong>HDR</strong>: The HTTP header &lt;name&gt; will be looked up in each HTTP request. Just as with the equivalent ACL &#39;hdr()&#39; function, the header name in parenthesis is not case sensitive. If the header is absent or if it does not contain any value, the round-robin algorithm is applied instead</pre><p>In our case, the HTTP header is “X-Unique-ID”. We configure this header using “<a href="https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#unique-id-format">unique-id-format</a>” and “<a href="https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-unique-id-header">unique-id-header</a>” options in HAProxy frontend configuration of PQS. We have used a combination of client IP and client port for the value of this header.</p><p>HAProxy HDR routing configuration:</p><pre>frontend phoenix<br>        bind 127.0.0.1:8888<br>        unique-id-format %{+X}o\ %ci:%cp<br>        unique-id-header X-Unique-ID<br>        option tcp-smart-accept<br>        option splice-request<br>        option splice-response<br>        default_backend phoenix_backend</pre><pre>backend phoenix_backend<br>        option tcp-smart-connect<br>        option splice-request<br>        option splice-response<br>        balance hdr(X-Unique-ID)<br>        server phoenix01 10.0.0.10:8765 maxconn 10 weight 1 check<br>        server phoenix02 10.0.0.11:8765 maxconn 10 weight 1 check</pre><p>The balancing will be done on the value of “X-Unique-ID” header which will pass traffic from frontend to backend. The header value (client IP and client port combination) will remain the same for a single HTTP keepalive connection. Therefore, HAProxy will always send all HTTP requests for a single keepalive session to the same PQS server.</p><h3>Conclusion</h3><p>HAProxy is a versatile piece of software, allowing you to shape traffic for any requirement. Our solution efficiently solves the stickiness requirement, providing better fault tolerance for Phoenix but can be used to solve any generic stickiness problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=911bdca7e2c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helpshift-engineering/smart-sticky-sessions-using-haproxy-for-apache-phoenix-911bdca7e2c">Smart sticky sessions using HAProxy for Apache Phoenix</a> was originally published in <a href="https://medium.com/helpshift-engineering">helpshift-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>