How does consul KV consistency works in regards to updating the same key

341 views Asked by At

If given a consul KV key a/key, where there are multiple agent server instances running, what happens if:

Two requests A (set value to val-a) and B (set value to val-b) are made to the create key endpoint without making use of the parameters cas or acquire in order to update the same key a/key:

  • If A and B are made in parallel can the key's value become corrupted?
  • Or if A comes slightly before B can the final value still become val-a?
1

There are 1 answers

0
Blake Covarrubias On

The data will not be corrupted if Consul receives two write requests at the same time. The write requests would be processed serially by the leader, so the value of a/key would become either val-a or val-b, whichever is processed last.

You can find details on how Consul writes data in Consul's Consensus Protocol documentation.