Hi Jesko,
to summarize, the idea is to get the full registry state with `getRegistryViaAQL` (i.e. in a stateless fashion), relying on the subscription to trigger updates.
To make this most efficient, I’d use `subscribeChunked` and collapse updates from events coming at around the same time.
Consistency of your AQL result with the streaming events you got so far can be obtained by specifying an `upperBound` to be used with the AQL query — this guarantees that the query only sees those events that were already seen by the subscription.
`subscribeChunked` already tracks the delivered OffsetMap for you, so the callback can just be
```
async (chunk: EventChunk) => {
const { ids } = getRegistryViaAQL(chunk.upperBound)
subs.next(ids)
}
```
I’d also pass `{ maxChunkTimeMs: 1000 }` (or some other suitable value) to reduce the number of queries to what you actually need — the default chunking time window is only 5ms.
OTOH, outside of chaos testing (which is a good idea but rather challenging) you can either control the presence of relevant events (in tests; thus not needing the upperBound) or you want the latest state in any case (in prod; also not needing the upperBound).
BTW (and just in case your omitted code doesn’t already have this): RxJS resource tracking can be somewhat obscure, but I think you need to forward errors and completions to the downstream subscriber as well. And I’d feed the `observeRegistry` stream into a `Subject` to avoid that multiple subscribers multiply the number of AQL queries executed — together with a built-in retry strategy this might well be good to package into this same function to avoid suboptimal usage.
Regards,
Roland