@SystemParadox I believe you are correct for a system based on locking. You don't have to use locks though. There are 100% safe lockless systems.
With the caveat that I've not actually implemented it, here is my (what I believe to be) 100% safe system:
- Partition the segement into sub-segments. Each shard owns a sub-segment.
- If we want to make a modification, read the entire segment, modify our sub-segment, write to the segment.
- On future ticks we know what our sub-segment should look like. Read the sub-segment and check. If it doens't look right that means we have a condented write which the other guy won. Skip a random number of ticks (or wallclock time) and goto 2. The skip probably isn't neccessary unless you're on >2 shards.
This method works around contention by brute force and can handle a shard just disappearing. High contention will cause delays but the random time length skipping should ensure that all writes go through without too much latency. It depends a bit on how much you're willing to tolerate. It's also possible that a shard will see another shard's subsegment go back in time causing some confusion. That can be sorted by having a timestamp in each subsegment.
If you're putting a lot in the segment then checking our section is correct every tick may bit a bit expensive. If you're only using it for small messages it shouldn't be.