Search code examples
restredisdapr

Is there a dapr.io design pattern to get all keys in the state store


In a containerized microservice I'm using the dapr.io state management system as a data cache of equipment; providing a highly efficient way of accessing many equipment status at scale.

Using a simple CRUD approach, I can create, read, update and delete equipment statuses using dapr as follows:

  • POST equipment/
  • GET equipment/key
  • PUT equipment/key
  • DELETE equipment/key

And my main problem is getting a list of all keys:

  • GET equipment

As dapr doesn't support a list of all keys in the state store, I need to track all keys separately using my own implementation.

https://github.com/dapr/docs/tree/master/concepts/state-management

I've tested two methods so far:

  1. SAGA pattern where POST/PUT/DELETE equipment calls publish events to an index API
  2. Manually manage the index in the equipment microservice POST/PUT/DELETE calls

In my view, the above methods add unnecessary complexity and create scale issues.

Is there a pattern for implementing a list of all keys using dapr without the above complexity?


Solution

  • Since release 0.10.0 there is an state API operation to get bulk state: https://github.com/dapr/docs/blob/master/reference/api/state_api.md#get-bulk-state