Loading page…
A social app must show how many times each post was opened in the last minute, updated on every open. Scanning the log makes about 5 billion reads for 100,000 opens. A map from each post to a queue of times answers each open in constant time on average. The same recipe builds a random pick with removal from a map and an array, a running average from two tables, short links, and the first unique id in a stream. A queue cannot give the least recently used item.
A social app shows, under every post, how many times it was opened in the last sixty seconds.