dapr / components-contrib

Community driven, reusable components for distributed apps
Apache License 2.0
544 stars 473 forks source link

Dapr Pub/Sub. Sending messages with specific fifoMessageGroupID #3415

Open YuryZevakin opened 4 months ago

YuryZevakin commented 4 months ago

Hello Guys, Thank you for DAPR. It helps a lot.

We are using AWS SNS/SQS pubsub in FIFIO mode and we want to set fifoMessageGroupID for each message we are sending. I have read Dapr.Client PublishEventAsync specification (for .net). Can we set fifoMessageGroupID in the parameters of PublishEventAsync?

Thank you in advance for your answer.

yaron2 commented 4 months ago

Moved this to the correct repository.

Can we set fifoMessageGroupID in the parameters of PublishEventAsync?

This is currently not supported. You can only set fifoMessageGroupID on the metadata, otherwise Dapr generates its own group ID for the message. I've triaged this into 1.14 as it should be easy to add.

YuryZevakin commented 4 months ago

Why is the ability to set fifoMessageGroupID when sending pub/sub messages important?

Background

we have an inventory system that is implemented according to the microservice architecture pattern and our microservices can communicate with each other with pub/sub pattern powered by DAPR. Each microservice has its own database and is responsible for its bounding context of the business domain.

As a result, we have a distributed system and we are working to reach the highest level of system consistency.

The most important tool to reach eventual consistency is by using FIFO queues in pubsub communications to make sure that all system operations will be processed in the system in the correct order. It is important to note that we have multitenancy in the system and many customers can use the system API in parallel.

AND

in the case of using FIFO all our customers currently are in one queue. And high load of one customer affects the work of another customer because the queue is FIFO and all messages will be processed in strict order. Horizontal scaling of microservices is useless in this case.

Proposes solution.

If we could set fifoMessageGroupID as customer Id, then processing to queues for different customers can performed in parallel. Horizontal scaling of microservices will work well and a high load of one customer will not affect to work of another customer in the multitenant system.

Workaround

Currently, we have a workaround, how to split processing to different customers with different FIFO, but is not as elegant as fifoMessageGroupID approach.

YuryZevakin commented 4 months ago

Thank you @yaron2 for a tip. I have set fifoMessageGroupID on the metadata.

var metaData = new Dictionary<string, string>(); metaData.Add("fifo", "true"); metaData.Add("fifoMessageGroupID", customerId);
_client.PublishEventAsync(pubsubName, topicName, data, metaData, cancellationToken);

I don't know Is it corrent way to set it so? Please advise me on how we can check fifoMessageGroupID was updated in SNS/SQS? Can i see it in some DAPR logs?

Thank you in advance.