I am new to golang and have a use case where operations on a value of a type have to run in a sequential manner where as operation on value of other type can be run concurrently.
- Imagine data is coming from a streaming connection (In-order)
key_name_1, value_1 key_name_2, value_2 key_name_1, value_1
- Now,
key_name_1
, andkey_name_2
can be operated by goroutine concurrently. - But as next streamed value (3rd row) is
key_name_1
again, so this operation should only be processed by goroutine if the earlier operation (1st row) has finished otherwise it should wait for the 1st operation to finish before it can apply the operation. For the sake of discussion we can assume that operation is simply adding the new value to previous value.
What would be the right way to achieve this in golang with highest possible performance ?
The exact use case is database changes are streamed on a queue, now if a value is getting changed its important that onto another database that operation is applied on the same sequence otherwise consistency will get impacted. Conflicts are rare, but can happen.