to remove two-column,resize your browser window to narrow
Singapore citizen, born in China. Graduate from National University of Singapore and University of Chicago. Happily married with kids. Loves reading, blogging, jogging, movies, programming.. This is the gmail-linked account.
in 2018, I have heard more and more sites that push the limits of stateless designs. I think this “stateless” trend is innovative and /bold/. Like any architecture, these architectures have “problems” and limitations, so you need to keep a lookout and deal with them and adjust your solution.
Stateless means simplicity, sometimes “extreme simplicity” (Trexquant)
Stateless means lightweight. Easy to “provision”, easy to relocate.
Stateless means easy scale-out.
Stateless means easy cluster. Http is an example. If a cluster of identical instances are stateless then no “conversation” needs to be maintained.
I got this question in a 2017 Wells white-board coding interview, and discussed with my friend Shanyou. We hoped to avoid locks and also avoid other synchronization devices such as volatile, atomic variables..
Q1: only a single producer thread and a single consumer thread and no other threads.
Q1b: Is it possible to avoid synchronization completely, i.e. single-threaded mode?
A: No. Consumer thread would have absolutely NO idea whatsoever how close it is to the producer end. No. We need a memory barrier at the very least.
Q2: what if there are multiple producer/consumer threads?
I believe we can use 2 separate locks for the two ends, rather than a global lock. This is more efficient but invites the tricky question “how to detect when the two ends meet“. I am not sure. I just hope the locks enforce a memory barrier.