Streams vs. Queues Cheat Sheet

This is a general comparison of streams and queues. Implementations may vary.

Stream and queue are alike and sometimes confused because they both acts as a buffer of ordered data, but they differ significantly otherwise.

StreamQueue
TypeContinuous dataDiscrete data
Useful UnitA series of dataIndividual data
Data StorageRemain in stream until expiredDeleted manually after processing
CursorUsing multiple cursors to read data from different positionsNo cursor, everyone reads from same position (FILO or FIFO)
Data HidingNo data hiding, after processing you set a new cursor and move onHides data for a brief period to prevent multiple workers processing the same data
Push/PullPullPull

Notable Use Cases

For stream, individual data do not make sense. For example, bank doing stats over a period of data, or video processing.

Single bits and bytes, a single transaction do not contribute much to the ends. Only when millions of transactions are processed then we have a useful result. When processing video we wait at least one more more frames are fetched from the stream to begin processing. Data flows continuously. Tiny bits of data in stream could be lost / duplicated without causing much trouble.

For queues, individual data makes all the difference. No matter it is a user transaction, login, or other business record, every single unit of data has a complete meaning and must be processed.

Though we could still batch processing multiple pieces of data at once, we processes then one by one, not as a whole as compared to streams.

Data in queues is usually important so duplication, lost data must be compensated and treated with care.