0

I have microservice that works with Couchbase. My service must ask Couchbase how many documents I have with the current id: if the number is low, I create another document.

My problem is that this is non-blocking: if I have a lot of requests when I first create a document, a second request also shows that the number of documents and is low (because first don't create yet document), so another new document is created.

To resolve this issue I created an actor system in akka with one actor per id, blocking (with Await) until the first is finished. This gives the order that I want. Is there a better way to do this?

But I have the issue when I add Kafka producer to this 'Await' Future, when kafka is down this future is blocking so long that I have timeout for Await. I put this producer in Future, but after this I don't have many threads in my Executor Context.

Prune
  • 76,765
  • 14
  • 60
  • 81

1 Answers1

0

I think you can use Circuit Breaker here: http://doc.akka.io/docs/akka/snapshot/common/circuitbreaker.html

I usually use this when I'm doing external service calls where that service has a tendency to be unavailable.