Erlang / Erlang Advanced Interview questions
Explain the internal working of selective receive and why message order in the queue matters?
A receive block doesn't necessarily take the first message in the mailbox — it scans the
queue in arrival order looking for the first message that matches any of its clauses, skipping over (but
leaving in place) messages that don't match, then removes only the one it matched.
flowchart LR
A[Mailbox: M1, M2, M3] --> B{Does M1 match a clause?}
B -->|No, skip| C{Does M2 match?}
C -->|Yes| D[Remove M2, bind it, continue with M1 and M3 still queued]
This is powerful — you can wait for a specific reply while ignoring unrelated traffic — but it
has a cost: the scan has to walk past every skipped message each time receive runs. If a process
accumulates a large backlog of messages that never match a narrow pattern, every subsequent
receive call gets progressively slower, since it re-scans that growing, unmatched backlog every
time. This is one of the classic causes of a process that seems to "slow down" under load without an obvious
CPU spike.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
