<?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 Miraz Al-Mamun on Medium]]></title>
        <description><![CDATA[Stories by Miraz Al-Mamun on Medium]]></description>
        <link>https://medium.com/@mal-mamun?source=rss-11847cf627cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z6WBDlxt3Ntma0Sd97R6KA.jpeg</url>
            <title>Stories by Miraz Al-Mamun on Medium</title>
            <link>https://medium.com/@mal-mamun?source=rss-11847cf627cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:01:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mal-mamun/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[Moving to ElastiCache Serverless for Redis to Improve Performance and Scalability]]></title>
            <link>https://medium.com/seek-blog/moving-to-elasticache-serverless-for-redis-to-improve-performance-and-scalability-a5ef008e03d0?source=rss-11847cf627cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5ef008e03d0</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[redis-data-migration]]></category>
            <category><![CDATA[elasticache-serverless]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Miraz Al-Mamun]]></dc:creator>
            <pubDate>Wed, 09 Oct 2024 23:46:25 GMT</pubDate>
            <atom:updated>2024-10-09T23:46:25.937Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Co-authored by: <a href="https://medium.com/u/a600141a0162">Shi Yuan</a>, <a href="https://medium.com/u/e64b9f7e01f">Dani Yang</a>, <a href="https://medium.com/u/11847cf627cb">Miraz Al-Mamun</a>, <a href="https://medium.com/u/367494cc4297">Divin Paul</a>, <a href="https://medium.com/u/2bc9ff5ed746">Manuel Weiss</a>, <a href="https://medium.com/u/3418fcf01c3c">Ben Swart</a></blockquote><p><em>This blog post describes our migration process from a self managed ElastiCache Redis cluster to an ElastiCache Serverless cluster. This could be of interest to you if you’re currently using or considering Redis for your production workloads and thinking about migrating to a Serverless version.</em></p><h3>Background</h3><p><a href="https://www.seek.com.au/about/">SEEK</a> is a market leader in online employment marketplaces, with an international presence that spans Australia, New Zealand and South-East Asia.</p><p>To help our users find their dream job, we provide personalised recommendations which generate a significant share of all job applications on SEEK. These recommendations are served through our website and mobile apps as well as through push notifications and emails.</p><h3>Using Redis in Recommendations</h3><p>To generate job recommendations, we consider the candidates’ behaviour, such as the jobs they viewed and applied for, along with their profile information and the details in the job advertisements. We use a number of different machine learning models; however for the purpose of this blog post we’ll focus on those that produce recommendations using candidates’ behavioural data. These models inherently learn the patterns of candidates’ preferences towards jobs and suggest more suitable jobs.</p><p>One challenge of these types of algorithms is the number of lookups of historical behaviour we have to make to generate a single set of job recommendations. So a single request to our API can easily cause many requests to our data store. We rely on Redis’ single-digit millisecond response time and its ability to handle <a href="https://redis.io/docs/data-types/">complex values like lists</a>, while allowing to <a href="https://redis.io/docs/manual/pipelining/">batch commands</a> together in a single request. At peak time, the Redis cluster handles about 25M commands/min, with the vast majority of those being reads.</p><h4>Architecture</h4><p>One of our behaviour-based Recommender Systems is using a <a href="https://arxiv.org/abs/1711.04101">Random Walk algorithm</a>, which “walks” over a graph of candidate-job interactions. This graph is stored in Redis as candidate-to-job and job-to-candidate mappings as shown in <em>Figure 1</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*JtLRjhf25mVL_kj-hkvUOw.png" /><figcaption><em>Figure 1. An example of a graph of user behaviour (left) built from candidate-job interactions stored in Redis (right).</em></figcaption></figure><p>To produce a set of recommendations for a single user, we have to retrieve a large number of such interactions from Redis as demonstrated in <em>Figure 2</em>. Because all this happens in realtime during request, a consistently low retrieval time is crucial. Redis is therefore an integral part of our Recommender Ecosystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*5CcGAxlp2FaAl7Y3kxjl3w.png" /><figcaption><em>Figure 2. High-level architecture diagram of Recommender System using Redis.</em></figcaption></figure><h4>Challenges with the Self-Managed Redis Cluster</h4><p>We cater to both real-time and offline experience. In real-time experience, candidates get recommendations on request in the mobile apps and on the website. While in offline experience, recommendations are computed in a batch process and candidates receive them via push notifications and emails.</p><p>The batch processing is scheduled during specific times of the day. When we are sending out Push Notifications, traffic to our recommendation systems, and therefore the load on Redis, increases dramatically, often tenfold. On top of that, the volume of traffic ebbs and flows throughout the day based on our users’ activity. With our self-managed ElastiCache Redis setup with <em>cluster mode disabled</em>, we managed this by horizontally scaling the Redis cluster on a schedule to meet the demand. Although effective initially, this approach eventually presented some challenges:</p><ol><li>We had reached the maximum allowable number of read replicas (0–5 for <em>cluster mode disabled</em>), leading to increase in latency during peak load.</li><li>We had to rely on the replicas scaling out on time to meet the traffic spikes. We were running a fairly large cluster and adding nodes took a long time, typically around 30 minutes. Because we scaled out and in on a schedule, this could easily cause issues when the batch processing took longer than normal or had to be run manually outside of the usual window.</li><li>To minimise costs, we implemented scheduled tasks to scale in the cluster after periods of high traffic. Nonetheless, this often resulted in our cluster being either under- or over-provisioned, as traffic patterns fluctuated due to changing user behaviour.</li><li>During times of heavy traffic with a high volume of write operations, the single write endpoint offered with <em>cluster mode disabled</em> was turning into a bottleneck.</li></ol><p>These challenges prompted us to consider migrating to a <em>Cluster Mode Enabled</em> Redis cluster to leverage the benefits of a distributed architecture like evenly distributed write load, better fault tolerance and scalability. This would have removed two crucial limitations of the old setup:</p><ul><li>With <em>cluster mode disabled</em>, the number of replicas is capped at 5, with all replicas receiving their updates from a single master node. With <em>cluster mode enabled</em>, you can have up to 500 nodes and writes are distributed across a configurable number of “shards”.</li><li>With <em>cluster mode disabled</em>, every node has a full copy of all data, which requires nodes that are large enough and also means new nodes are only ready to serve traffic when all data has been copied onto them. With <em>cluster mode enabled</em>, a larger number of much smaller nodes can be used which makes the scaling more elastic.</li></ul><p>As we were preparing for this in late November 2023, <a href="https://aws.amazon.com/blogs/aws/amazon-elasticache-serverless-for-redis-and-memcached-now-generally-available/">AWS introduced ElastiCache Serverless for Redis</a>, offering fully elastic scaling and pay-for-use billing. This appeared to offer a solution to the challenges we had previously discussed so we decided to give this a try.</p><h3>Migration to ElastiCache Serverless for Redis</h3><h4>Data Migration</h4><p>In our self-managed Redis cluster (with <em>cluster mode disabled</em>), we partitioned the data into multiple databases, each of which holds different datasets. ElastiCache Serverless uses cluster mode and only supports one database (database 0). Unfortunately, there’s no built-in way to migrate data from a Redis instance with multiple databases to ElastiCache Serverless. Therefore we used <a href="https://github.com/redis-developer/riot">RIOT</a> to perform the data migration between the clusters manually.</p><pre>riot -h &lt;source ElastiCache host&gt; -p &lt;source ElastiCache port&gt; --db &lt;index&gt; replicate -h &lt;target ElastiCache host&gt; -p &lt;target ElastiCache port&gt; --cluster</pre><p>It’s important to note that the migration script needs to be executed for each database index in the source cluster. Also, this requires that there are no clashes between keys. Luckily, all our keys were already prefixed with namespace identifiers to make them globally unique.</p><p>As shown in <em>Figure 3</em>, we restored a separate Redis instance from a backup to ensure isolation from the production environment, migrated the data using RIOT from this backup instance to ElastiCache Serverless, and handled any incremental changes by re-feeding them from upstream.</p><figure><img alt="Image of Redis Data Migration Process workflow" src="https://cdn-images-1.medium.com/max/700/1*IVseLfq2zlQXJuSVh5yZ9g.png" /><figcaption><em>Figure 3. Process of data migration and data replay to ElastiCache Serverless.</em></figcaption></figure><h4>Go-redis Client Changes</h4><p>ElastiCache Serverless operates with <em>cluster mode enabled</em> configuration and requires Redis clients to use TLS transport and the Redis cluster topology. As the Recommender System is written in <em>golang</em>, we looked into the required changes for the client to adapt.</p><p>Here is an example code snippet (go/redis v9) for connecting to ElastiCache Serverless (for read-only connections), as illustration:</p><pre> client := redis.NewClusterClient(&amp;redis.ClusterOptions{<br>   Addrs:        []string{addr},<br>   PoolSize:     1000,<br>   MinIdleConns: 100,<br>   TLSConfig:    &amp;tls.Config{MinVersion: tls.VersionTLS13},<br>   ReadOnly:     true,<br> })</pre><p>ElastiCache Serverless utilises port 6379 primarily to allow both read and write operations, while the the port 6380 facilitates lower-latency reads from any replicas via the <a href="https://redis.io/docs/latest/commands/readonly/">READONLY</a> command mode.</p><h4>Data Integrity</h4><p>To ensure the integrity and accuracy of data following migration, our validation process included comparing key counts and conducting sample checks. Furthermore, we performed shadow tests to evaluate the consistency of recommendations generated from ElastiCache Serverless and those from our self-managed Redis cluster.</p><h3>Performance Comparison</h3><p>As highlighted in the <em>Challenges</em> section, one of the major challenges we faced was our self-managed cluster reaching its scaling limit during peak traffic, resulting in latency increases and timeouts.</p><h4>Self-Managed Cluster (with cluster mode disabled)</h4><p>During peak hours, <strong><em>EngineCPUUtilization</em></strong> consistently surpassed 95%, signifying a high load on the Redis replicas as illustrated in the top image of <em>Figure 4</em>. This caused performance degradation and a notable increase in timeouts, impacting our downstream consumers.</p><p>We also observed large spikes in <strong><em>NetworkBandwidthOutAllowanceExceeded</em></strong>, signalling that our cluster’s traffic exceeded the allocated bandwidth limit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*nqCkCcpCTW_8FdZ44lpd1w.png" /><figcaption><em>Figure 4. Engine CPU Utilization (top) and Network Bandwidth Out Allowance Exceeded (bottom) of the self-managed Redis cluster with cluster mode disabled on a day</em> <em>before migration. There is a batch process running between 3am and 9am that is causing the CPU load but does not cause significant network load.</em></figcaption></figure><h4>ElastiCache Serverless Cluster</h4><p>ElastiCache Serverless scales automatically according to CPU, memory and bandwidth requirements. It abstracts low-level CPU and bandwidth metrics, providing performance monitoring through the following metrics instead:</p><p><strong><em>ElastiCacheProcessingUnits</em></strong>: This indicates the eCPUs consumed by our workload, serving as our new metric for CPU utilization.</p><p><strong><em>ThrottledCmds</em></strong>: This represents the number of throttled commands, providing insight into the ability of the Redis cluster to meet demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*F1AdNoccbv1rBDbR8vqGHQ.png" /><figcaption><em>Figure 5. ElastiCache Processing Units (top) and Throttled Commands (bottom) of</em> ElastiCache Serverless cluster<em> on a typical day after migration. Note: Network Bandwidth Allowance Exceeded is not reported for ElastiCache Serverless and ThrottledCmds can be used as a representative metric.</em></figcaption></figure><p>As shown in <em>Figure 5</em>, our new ElastiCache Serverless cluster delivers notably improved scalability and performance, while also eliminating the necessity for any capacity planning.</p><h3>Cost Comparison</h3><p>As Redis is one of our main cost factors in the Recommendations ecosystem, keeping costs under control was paramount to the viability of migrating to the ElastiCache Serverless solution. While some back-of-the-envelope calculations during the planning phase had given us some confidence that we would not completely blow out our budget, we were ready to pay a premium for a stable system that required next to no maintenance.</p><p>In our previous setup we were running fairly large <em>r6g.8xlarge</em> instances where we were charged based on the instance type and the number of instances running, which fluctuated between 1 and five replicas plus the master node. Transitioning to the new Serverless solution comes with a new dynamic pricing structure based on two dimensions: <a href="https://aws.amazon.com/elasticache/pricing/">Data storage and ElastiCache Process Units (ECPUs)</a>.</p><p>Following the transition to Serverless Redis, we observed that the cost of the ElastiCache Serverless cluster was marginally higher compared to the self-managed cluster for our specific use case. However, through data storage optimisation, we managed to reduce the cost to be roughly on par with the self-managed cluster. This was achieved because we are paying solely for the stored data, eliminating the cost of running the large instances.</p><p>The core cost benefits associated with the Serverless solution come from the fact that we only pay for use without having to provision enough headroom for fluctuating demand. Unlike traditional on-demand instances where resources are provisioned ahead-of-time, often leading to over-provisioning, the Serverless model scales dynamically with our workload demands, eliminating the need to pay for idle capacity. Another large benefit is that we don’t have to constantly tweak things anymore to balance cost and stability. However, it is important to keep an eye on usage to avoid costly surprises!</p><h3>6 Months Later</h3><p>Looking back, we haven’t had any performance issues with the new ElastiCache Serverless cluster and zero maintenance overhead of scaling the cluster or applying security patches.</p><p>We also performed a Disaster Recovery exercise where we rebuilt the cluster from a backup in Production. We did not run into any issues and were happy with the time to restore.</p><h3>Conclusion</h3><p>In summary, adopting ElastiCache Serverless has brought significant benefits to our recommendation systems, including improved scalability, enhanced reliability, simplified management of infrastructure resources, and costs that are on par with those of the self-managed cluster.</p><p>The transition to ElastiCache Serverless was prompted by challenges faced with the self-managed Redis cluster, particularly during peak traffic periods. The automatic scaling and resource allocation of ElastiCache Serverless have addressed these challenges, ensuring consistent performance and reliability. This has empowered our team to concentrate on building better recommendation systems rather than infrastructure management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5ef008e03d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/seek-blog/moving-to-elasticache-serverless-for-redis-to-improve-performance-and-scalability-a5ef008e03d0">Moving to ElastiCache Serverless for Redis to Improve Performance and Scalability</a> was originally published in <a href="https://medium.com/seek-blog">SEEK blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>