A Gentle Intro to Streams

Feather
The Startup
Published in
3 min readJan 6, 2021

--

An overview of working with live data — and yet another reason to love Elixir

Autumn Flax, silkscreen, by Feather Knee

Most of us have watched Netflix, so we know conceptually what streaming data means. Working with streaming data in code can seem much more intimidating than catching up on past episodes of your favorite shows. Understanding the why of things will make dealing with streaming data in any language more intuitive.

Whenever data is live updated continuously, you have a stream. It could be something continuous like music or video. It could also be a contiguous series of live data updates such as a Twitter feed or stock prices. It could even be a series of mouse coordinates in a UI.

Either way, you can think of a stream as being sort of like an Array, but infinite in length. If you try to work with this data using the same tools you would reach for with for finite data, it’ll cause problems.

Suppose you have an Array of recent Apple stock prices. These can give you an idea of where the stock has been lately, but it won’t really answer the question of how much you would pay if you were to buy 5 shares right now. If you want to provide the most recent price, you will need a stream of live-updating data.

If you continue using an Array to store this data, you will end up with a fresh copy of the whole data set each time the price…

--

--

Feather
The Startup

Thoughts on code, climbing, and DIY. JavaScript, Elixir, and other fun stuff.