<p>I'm using:</p>
<ul>
<li><strong>Azure platform</strong> to run some <strong>microservice architecture</strong> software solution.</li>
<li>microservices are using the <strong>Azure-EventHub</strong> for communicating in special cases.</li>
<li><strong>Kubernetes</strong> with 2 clusters (primary, secondary)</li>
<li>per application namespace, there is 1 event-listener pod running per cluster for consuming from eventhub</li>
</ul>
<hr />
<p>The last point is relevant to my current problem:
The load balancers will share traffic between the primary and secondary clusters. This means that 2 event-listener-pods are running per application at the same time. So they are just reacting to events but some times they are consuming the same event from the event hub and this causes some duplicated notification mails.</p>
<p>So finally my question is: How can I avoid reading the same event twice the same time? I thought event hub index is always increasing but starting at the same moment is not &quot;secured&quot;.</p>

<p>You will need to use separate consumer groups per pod to <a href="https://stackoverflow.com/questions/51441518/epoch-error-while-communicating-with-azure-event-hub">avoid EPOCH error</a>.</p>
<p>That said, both pods will read the same events, so you have two options.</p>
<ol>
<li><p>Have an active-passive set up. One consumer group, one pod that reads the events and delegates the work out on each event. If that pod fails, then a health/heart beat mechanism brings the second pod online.</p>
</li>
<li><p>Have an active-active set up. Two consumer groups, two active pods. You will need to implement idempotent processing.</p>
</li>
</ol>
<p>Idempotent processing, where processing the same message multiple times produces the same result, is good practice regardless of approach. This would allow you to replay batches of events in which one errored and not have adverse affects on the integrity of your data.</p>
<p>I would opt for the first option, a single event hub reader will process thousands of events per second and pass off the work to your micro services.</p>
<p>If you have lower volumes of messages and need guaranteed message processing, then using Service Bus may be a better choice where messages can be locked, completed and abandoned.</p>
