https://slatedb.io logo
πŸ‘‹ Quick question: How do you keep a writer highl...
# general
j
πŸ‘‹ Quick question: How do you keep a writer highly available? I see opening a new instance fences the current writer, so simply having multiple pods in a retry loop isn’t viable. Is there a built‑in / easy way to detect if there is active writer?
c
Good question! We don't have a built-in way to detect an active writer right now. Off the top of my head, the easiest thing to do is probably to poll the manifest regularly to see if it's being updated. If it's not, you can treat the writer as dead, and instantiate a new writer. This approach would work, but would create a little bit of churn. You'd presumably have multiple instances all polling, and they'd all decide a writer is dead at the same time. Thus they'd all try and fence each other and the last writer would win. You could introduce some skew amongst the pollers to try to prevent too much churn, though.
I had also considered bolting on Quickwit's Chitchat library, which would allow clients to gossip about who the writer is.
If you have more thoughts about how best to address this, I'm definitely interested. πŸ™‚
j
is it supposed to work as a distributed system? I thought it was firmly in the single-node camp. that said, if you start adding gossip, then you've got distributed system issues πŸ˜„ you could possibly use S3's conditional puts to handle some kind of lock to determine the current writer?
c
It is firmly single node
w.r.t. chit-chat, I was thinking about it more as a fun separate project
> you could possibly use S3's conditional puts to handle some kind of lock to determine the current writer We already do that. That's how writer fencing works.
Writer fencing is discussed here: https://github.com/slatedb/slatedb/blob/main/rfcs/0001-manifest.md but tl;dr is we do CAS using s3 precondition on WAL writes
j
Thanks for help πŸ™‡ > Off the top of my head, the easiest thing to do is probably to poll the manifest regularly to see if it's being updated. If it's not, you can treat the writer as dead, and instantiate a new writer. I was thinking something similar: * Read the manifests * See no activity * Wait some jitter time * Recheck the manifests and then start a new writer > I had also considered bolting on Quickwit's Chitchat library, which would allow clients to gossip about who the writer is. πŸ‘€ I'll have a look it but seems overly complicated. Sounds like doing something with S3 CAS is probably a good first option.
> We already do that. That's how writer fencing works. Might be interesting to have some sort of metadata as a part of the writer creation, so we could consistently read it and figure out who the current writer is, so we can forward writes.
c
Yep, yep. Sounds totally reasonable. If you're going to do something with S3 CAS, you might as well just use the manifest polling since it is using S3 CAS under the hood.
Could just treat manifest updates as a heartbeat. Only thing is if you want to decouple heartbeat from both manifest and WAL write intervals
Then you'd be better off having the writer write to some random file every so often
(that opens up a window where a writer could be happily updating the heartbeat file while the SlateDB write path is totally deat, but I digress...)
s
I think a client side coordination logic( depending on how the SlateDb client is embedded ) example a kubernetes service, a kafka streams app, etc can leverage mechanisms provided by their ecosystem to determine the coordination and the leader. A possible approach could be that the Leader would always be a writer and rest of the clients would act as a reader( which would turn into a writer when chosen as leader) ensuring writer availability
c
Ya, this was the thinking behind our decision to keep the single writer design
p
This discussion really makes me think my theory olds up https://github.com/Barre/ZeroFS?tab=readme-ov-file#cap-theorem
If the client coordinates who becomes the next writer, there's no other coordination required