<p>I have few consumers which updates their local cache on reading a message from the kinesis queue. But this leads to inconsistency as message is only processed by only one among all the replicas and any information retrieved from other replicas gives us invalid cache.</p>
<p>How can i make sure i clear the cache among all the replicas when the invalidation message appears in the queue.</p>

Chakri
<p>The library that you're using assigns consumers to shards, so any message that you put on the stream will only go to one consumer.</p>
<p>The best solution would be to send your invalidation message out-of-band, using another Kinesis stream (or alternative such as SNS). This would add  complexity to your listener, as they'd now have to listen for two sources (and you couldn't use that library for the out-of-band messages).</p>
<p>If you want to send in-band cache invalidation messages, then you need to write the validation message multiple times, with different partition keys, so that it goes to all shards in the stream. The way that the partition key works is that it's MD5-hashed, and that hash is used to select a shard (see <a href="https://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecord.html" rel="nofollow noreferrer">PutRecord doc</a>).</p>
<p>Assuming that your application can handle multiple cache invalidation messages, I think that the best way to handle this is to write multiple messages with different partition keys (no need to get fancy, just use &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, and so on). Keep doing this until you've written a message to every shard (getting the shard ID for each record from the response to <code>PutRecord</code>).</p>
<p>You can call <a href="https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListShards.html" rel="nofollow noreferrer">ListShards</a> with a <code>ShardFilter</code> of <code>AT_LATEST</code> to get the shard IDs of the currently active shards.</p>
