1

I know the java DynamoDB's SDK is considered async non blocking but my question is:

Q. Does the dynamo update still need to be on another thread with operator publishOn to be safer in a reactive context?

Mono.fromFuture(table.update()).publishOn();

M_K
  • 3,247
  • 6
  • 30
  • 47

1 Answers1

1

Assuming that you are using the AWS Java SDK v2, you don't need to worry about delegating to a thread pool. AWS SDK already makes sure that you don't block an important thread. See documentation for details:

The AWS SDK for Java 2.x uses Netty, an asynchronous event-driven network application framework, to handle I/O threads. The AWS SDK for Java 2.x creates an ExecutorService behind Netty, to complete the futures returned from the HTTP client request through to the Netty client. This abstraction reduces the risk of an application breaking the async process if developers choose to stop or sleep threads. By default, 50 Threads are generated for each asynchronous client, and managed in a queue within the ExecutorService.

Actually, it even use more threads than it would be desired in a truly reactive application. Fortunately, the SDK also gives option to opt out of that behavior if needed.

One more thing that's good to be aware of is CompletableFuture is eager unlike reactive type Mono. For this reason it is better to use the lambda version of the fromFuture method:

Mono.fromFuture(() -> table.update())
Martin Tarjányi
  • 8,863
  • 2
  • 31
  • 49
  • Thanks for this info, I am using the 2.x SDKs. so if I used publishOn() then I would not be using the above AWS thread pool and use the Netty bounded thread pool, is there any downsides to using bounded instead? – M_K Feb 16 '22 at 23:07
  • No, AWS would still switch to its own thread. Unless you setup AWS client as in the last example on this page: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/asynchronous.html#advanced-operations – Martin Tarjányi Feb 17 '22 at 07:47