The light you see is already part of the past
Looking at the sky is looking at the past. And every distributed system lives with the same dilemma.
You know that line everyone has heard, that the star you're looking at might not even exist anymore? It's half true, half exaggeration. And the true half has everything to do with what we do every day as programmers.
Grab a coffee and come with me.
Light takes time too
In a vacuum, light travels at about 300,000 kilometres per second. It feels instantaneous, and for almost everything in our lives it is. But the universe is big enough for that "almost" to show up.
| What you're looking at | How long its light takes to reach you |
|---|---|
| The Moon | a little over 1 second |
| The Sun | about 8 minutes and 20 seconds |
| Proxima Centauri, the nearest star after the Sun | about 4.2 years |
| Betelgeuse, Orion's shoulder | several centuries. NASA uses an estimate of about 700 years |
| The Andromeda galaxy | about 2.5 million years |
As a thought experiment, if the Sun vanished right now, you'd keep seeing it for another eight minutes. And when you look at Andromeda on a dark night, the light reaching your eye left it before our species existed.
Looking at the sky is never looking at the present. It's always an old photograph, and every point of light is a photograph from a different time.
So the star is already dead?
This is where the exaggeration comes in. Most of the stars you can see with the naked eye are relatively close, a few dozen or a few hundred light-years away. And stars live for millions or billions of years. The chance that one of them died precisely during the time its light was travelling to you is small.
Betelgeuse is the famous candidate: it's a red supergiant near the end of its life, and one day it will explode. Even at this stage, it could still take a long time. The estimates depend on how far along the star is. So yes, the image is from the past. But almost always, the star is still there.
What you see isn't false. It's true for the moment the information left. The problem only shows up when you forget that.
Now swap "star" for "server"
If you work with systems, this idea has crossed your desk many times, under other names.
Latency. A request from São Paulo to a server in the United States crosses thousands of kilometres of fibre. Even at the speed of light inside glass, which is slower than in a vacuum, physics alone already charges a few dozen milliseconds for the round trip. Code can cut processing time. Reducing the time the signal spends in the fibre takes a shorter route.
Caching. Every time you keep a copy of some data to answer faster, you're looking at a star: the information was true when it was stored. If a list of posts stays in an edge cache for 60 seconds, an edit made during that window may take a while to show up. In return, fewer visits need to reach the origin server.
Replicas and eventual consistency. In a database with replicas, you write to the primary and read from a copy that may be a few milliseconds behind. The copy isn't wrong; it's in the past. If writes stop and the replicas converge on the same state with no guaranteed deadline, that's an example of eventual consistency.
The classic bug
A user saves their profile, the page reloads reading from a replica that hasn't received the write yet, and they see the old data. To them, the system "didn't save". The fix is usually to read from the primary right after a write, just for whoever wrote.
There's no "now" for everyone
There's an idea in physics that goes even deeper. Einstein's relativity shows that two observers in different states of motion can disagree about whether two events happened at the same time. There's no universal clock everyone can check.
In 1978, Leslie Lamport published a paper called Time, Clocks, and the Ordering of Events in a Distributed System, one of the most cited texts in computing. And he himself has said the inspiration came from relativity: if physics doesn't guarantee a shared "now", a system made of many machines doesn't either. What you can guarantee is the order of cause and effect, and that's what he created logical clocks for.
That's why, in distributed systems, "which happened first?" is a much harder question than it looks. And that's why we use things like versions, queues and logical clocks to deal with ordering. Idempotency keys address a different problem: retrying an operation without repeating its effect.
UTC helps, but doesn't solve it alone
Storing everything in UTC takes the time zone, which is a representation problem, out of the picture. But it doesn't synchronize the clocks: two machines can disagree by tens of milliseconds even when both are on UTC, and that's why, when order really matters, versions and logical clocks are worth more than the time of day.
What to take away
- Any data that came from far away or was stored is a photograph of the past.
- That's not a defect; it's physics. The defect is treating the photograph as if it were the present.
- For every cache or replica, decide how much delay is acceptable and make it explicit.
- When order matters, don't trust each machine's clock.
Next time you step outside at night and look at Orion, find Betelgeuse, the reddish one on his shoulder. The light reaching you left it a few centuries ago, depending on which measurement you use. And it's still perfectly valid, as long as you remember when it was sent.
It's the best reminder I know that every piece of data has a date.