AWS Kinesis – Uniform Data Distribution Across Shards

AWS Kinesis

About the author

As a seasoned data engineer, Akshay has led data management initiatives at distinguished firms such as Amazon, and Visa. His expertise lies in implementing large-scale data solutions, advanced analytics, optimising ETL processes, anomaly detection, and NLP. He has also helped organisations like AWS to manage streaming data at scale and to support analytics over it using AWS services. 


Amazon Web Services Kinesis is key in data streaming, helping process and analyse data in real time. Important for developers, data engineers, and analysts, learning Kinesis improves how you manage data and makes projects more responsive and efficient. 

However, challenges exist. One major issue is data not spreading evenly across Kinesis shards, leading to delays and potential data integrity problems.

Why does this uneven distribution occur, and what are its repercussions on your data streaming projects? More importantly, how can you monitor and rectify this imbalance to ensure seamless data flow and maximum utilisation of Kinesis’s potential? This article delves into the heart of these questions. Before we proceed, a foundational understanding of AWS Kinesis is recommended. If you’re new to Kinesis or seeking a refresher, consider reviewing its official documentation to maximise the benefits of the insights shared here.

Let’s dive into Kinesis data streams together. We’ll look at why data doesn’t always spread out as it should and show you how to fix these issues. This information is valuable whether you’re well-versed in the field or just starting. By the end, you’ll be better equipped to use AWS Kinesis to its fullest in your data projects.

Understanding the Problem

At the heart of AWS Kinesis is the data stream, made up of data shards. Each shard is crucial for managing data, allowing for both adding and accessing data. Getting to know how these shards work is key because they affect how well and how big your data processing can get. A big part of a shard’s job involves the partition key that decides how data is spread out over shards.

Choosing a partition key when sending data to a stream matters a lot as it shapes how your data moves. AWS turns these keys into unique number values using an MD5 hash function, and these numbers determine which shard a piece of data goes to. Ideally, this mechanism should ensure a balanced distribution of data across all shards, resembling the uniformity shown in image 1 below:

uniform distribution of records across shards

However, the real-world scenario often deviates from this ideal. The crux of the issue lies in the selection of partition keys. If these keys lack randomness, the MD5 hash function may consistently map a disproportionate amount of data to specific shards. This results in an uneven load, with certain shards receiving more data than others, as depicted in image 2:

non-uniform distribution of record across shards

This uneven distribution can precipitate what’s known in AWS parlance as the “hot shard” problem.

Imagine a scenario where your application tries to push data at a rate exceeding the maximum throughput of a shard. The immediate consequence is a WriteThroughputExceeded error. Such a bottleneck not only hampers the real-time processing capability of your stream but also risks data integrity. Moreover, a persistent imbalance in shard utilisation can lead to increased occurrences of WriteProvisionedThroughputExceeded metrics in AWS CloudWatch, signalling throttle errors and potential data loss.

By closely examining how partition keys influence data distribution and identifying the manifestations of shard overloading, you set the stage for a deeper exploration into monitoring techniques and corrective strategies that ensure a seamless, efficient data flow across all Kinesis shards.

Monitoring Data Distribution

Recognizing the significance of evenly distributed data across Kinesis shards for the seamless execution of your projects, monitoring becomes an indispensable practice. But how do you accurately track the flow of data across shards to identify potential imbalances? Below I offer for your consideration two robust approaches, each designed to provide deep insights into your data distribution patterns, empowering you with the necessary tools to maintain the optimal performance of your AWS Kinesis streams.

Approach 1: Utilising AWS Enhanced Monitoring

The first line of defence against uneven data distribution is AWS’s enhanced monitoring capabilities. By enabling the EnableEnhancedMonitoring API, you unlock a more granular view of your stream’s performance at the shard level. This feature provides you with critical metrics such as IncomingBytes and IncomingRecords, which reflect the volume of data ingested into each shard. Furthermore, metrics like WriteProvisionedThroughputExceeded and ReadProvisionedThroughputExceeded offer clear indicators of any throttling issues, pinpointing shards that are under excessive load. Visualising these metrics on a CloudWatch dashboard offers a snapshot of your stream’s health, guiding your optimisation efforts. Picture the clarity achieved through such a detailed monitoring setup, as depicted in image 3 below, where every metric tells a story of your stream’s operational efficiency.

CloudWatch dashboard snapshot with several metrics of a Kinesis data stream

Approach 2: Custom Dashboards via Logging

While AWS’s built-in monitoring tools offer comprehensive insights, sometimes a more tailored analysis is required. This is where custom dashboards come into play, leveraging logged responses from your producer and consumer applications. By customising the logging process, you can capture detailed information about the success of data write operations and the specific shards receiving data.

Logging on the Producer Side

When your application writes data to Kinesis, the PutRecord API response includes the shard ID where the data was stored. By systematically logging these responses, you can construct a custom dashboard that visually represents the distribution of data across shards. This bespoke approach not only enhances your monitoring capabilities but also allows you to pinpoint the root causes of uneven distribution with unparalleled precision.

Logging on the Consumer Side

Similarly, on the consumer side, implementing custom logging within your IRecordProcessor implementation enables you to track the volume of data processed from each shard. By aggregating this data, you can develop dashboards that reflect real-time data consumption patterns, offering insights into potential bottlenecks or underutilised resources within your stream.

By adopting one or both of these monitoring strategies, you place yourself in a commanding position to assess and address the distribution of data across your Kinesis shards. Whether you opt for the comprehensive overview provided by AWS enhanced monitoring or the detailed analysis enabled by custom dashboards, you are well-equipped to ensure that your data streaming infrastructure operates at its peak efficiency, guaranteeing the reliability and performance of your data-driven projects.

Solutions for Uniform Data Distribution

Having explored the challenges of uneven data distribution across Kinesis shards and the monitoring strategies to identify such issues, the pivotal question now is: How do we rectify this imbalance? Achieving uniform data distribution is not just beneficial — it’s imperative for optimising the performance of your AWS Kinesis streams. Here, we detail practical solutions that can be seamlessly integrated into your data management strategy to ensure balanced shard utilisation.

Utilising Partition Keys Effectively

A cornerstone technique for distributing data evenly across shards is through the strategic use of partition keys. By assigning each record a unique partition key, ideally through randomisation, you significantly increase the chances of achieving a uniform distribution. This method leverages the inherent design of Kinesis, where the MD5 hash function maps each unique partition key to a shard in a manner that aims to balance the load across all shards. Imagine assigning each piece of data a random identifier, much like handing out unique tickets for an event, ensuring no single entry point becomes overwhelmed. This strategy not only mitigates the risk of creating hot shards but also maximises the throughput efficiency of your stream.

Employing Explicit Hash Keys

Another powerful approach involves the use of explicit hash keys. Unlike the partition key, which indirectly determines the shard a record is assigned to, an explicit hash key allows you to specify precisely which shard should receive the data. This method requires a deeper understanding of your stream’s shard configuration but offers unparalleled control over data distribution.

By providing an explicit hash key with your API call, you effectively bypass the partition key’s role in shard assignment. This direct approach enables you to distribute data evenly by manually specifying the shard based on its hash key range. Below is an illustrative example of how shard information can be utilised:


    “Shards”: [


            “ShardId”: “shardId-000000000000”,

            “HashKeyRange”: {

                “EndingHashKey”: “170141183460469231731687303715884105727”,

                “StartingHashKey”: “0”


            “SequenceNumberRange”: {

                “StartingSequenceNumber”: “49600965817078608863948980125442188478720910276534730754”




            “ShardId”: “shardId-000000000001”,

            “HashKeyRange”: {

                “EndingHashKey”: “340282366920938463463374607431768211455”,

                “StartingHashKey”: “170141183460469231731687303715884105728”


            “SequenceNumberRange”: {

                “StartingSequenceNumber”: “49600965817100909609147510748583724196993558638040711186”





Using the above information, you can craft keys that fall within the specific hash key ranges of your shards. Implementing a round-robin algorithm further enhances this strategy, distributing records sequentially across all shards, thereby ensuring each shard receives an equal share of the data load. This method not only guarantees uniform data distribution but also facilitates efficient utilisation of your stream’s capacity.

In mastering AWS Kinesis, ensuring even data distribution across shards is key to optimising your projects. This guide provided strategies for addressing uneven distribution, from using partition keys effectively to employing explicit hash keys for precise control.

As we wrap up, remember that the tools and techniques shared here are just the starting point. Continuously refine your approach to keep your data-driven applications performing efficiently. With the insights gained today, you’re equipped to enhance your projects, ensuring high performance and reliability in your real-time data processing endeavours.

To Top

Pin It on Pinterest

Share This