<p>I have a collection in my Cosmos database that I would like to observe for changes. I have many documents (official and unofficial) explaining how to do this. There is one thing though that I cannot get to work in a reliable way: how do I receive the same changes to multiple instances when I don't have any common reference for instance names?</p>
<p>What do I mean by this? Well, I'm running my work loads in a Kubernetes cluster (AKS). I have a variable number of instances within the cluster that should observe my collection. In order for change feeds to work properly, I have to have a unique instance name for each instance. The only candidate I have is the pod name. It's usually on the form of <code>&lt;deployment-name&gt;-&lt;random string&gt;</code>. E.g. <code>pod-5f597c9c56-lxw5b</code>.</p>
<p>If I use the pod name as instance name, all instances do not receive the same changes (which is my requirement), only one instance will receive the change (see <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed-processor#dynamic-scaling" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed-processor#dynamic-scaling</a>). What I can do is to use the pod name as feed name instead, then all instances get the same changes. This is what I fear will bite me in the butt at some point; when peek into the lease container, I can see a set of documents per feed name. As pod names come and go (the random string part of the name), I fear the container will grow over time, generating a heap of garbage. I know Cosmos can handle huge work loads, but you know, I like to keep things tidy.</p>
<p>How can I keep this thing clean and tidy? I really don't want to invent (or reuse for that matter!) some protocol between my instances to vote for which instance gets which name out of a finite set of names.</p>
<p>One &quot;simple&quot; solution would be to build my own instance names, if AKS or Kubernetes held some &quot;index&quot; of some sort for my pods. I know stateful sets give me that, but I don't want to use stateful sets, as the pods themselves aren't really stateful (except for this particular aspect!).</p>

Jörgen Sigvardsson
<p>There is a new <a href="https://learn.microsoft.com/azure/cosmos-db/change-feed-pull-model" rel="nofollow noreferrer">Change Feed pull model</a> (which is in preview at this time).</p>
<p>The differences are:</p>
<p><a href="https://i.stack.imgur.com/85phA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/85phA.png" alt="change feed push model versus change feed processor" /></a></p>
<p>In your case, it looks like you don't need parallelization (you want all instances to receive everything). The important part would be to design a state storing model that can maintain the continuation tokens (or not, maybe you don't care to continue if a pod goes down and then restarts).</p>
