I am attempting to create a system where there is an ordered, global array of information that is shared by each server and updated semi-regularly. This array is currently stored in a datastore, and each server periodically appends data to the array. Here’s a potential problem I see happening:
- Server 1 reads the array {“item1”,“item2”,“item3”} and caches it.
- Server 2 reads the array {“item1”,“item2”,“item3”} and caches it.
- Server 1 appends an item to the array and writes it to the datastore. The array is now {“item1”,“item2”,“item3”,“Foo”}
- Server 2 appends an item to the array and writes it to the datastore. The array is now {“item1”,“item2”,“item3”,“Baz”}
Since Server 2 did not see that Server 1 had appended something to the array, server 1’s update was overwritten, resulting in data loss. Is this a real problem or am I just overthinking this? I have a few possible solutions in mind but none of them seem very elegant.