
The Illusion of Realtime in Computing
In software development, we often talk about "realtime" as if it's a definitive concept—messages sent instantly, updates reflected immediately, data synchronized across systems without delay. But what does "realtime" actually mean? And does it truly exist?
From event ordering to WebSockets, let's break down what makes realtime computing possible, the illusion behind it, and why time itself is a tricky thing to grasp.
No Two Events Happen at the Same Time
At the fundamental level of physics, no two events can ever truly occur at the same moment. Everything exists within a sequence, even if that sequence is measured in nanoseconds.
When we say two things happened “at the same time,” what we really mean is that they occurred so closely together that the difference is imperceptible to us. But if we zoom in far enough, even the fastest events are still sequential.
Computers, which rely on clock cycles, registers, and atomic operations, inherently process instructions in sequence—even in massively parallel systems. There is always an ordering, even when it appears simultaneous. The challenge in "realtime" software is making this ordering invisible to users.
Time: A Human Construct vs. a Physical Reality
Time as we experience it is a human abstraction. We impose seconds, milliseconds, and timestamps on the world to make sense of sequences of events. Physically, however, time is relative—Einstein's theories tell us that time moves differently based on gravitational fields and relative velocities.
In computing, time is represented in absolute terms (timestamps, system clocks, event logs), but these are just approximations. No two machines perfectly agree on time. Network latency, hardware drift, and CPU scheduling introduce tiny inconsistencies, which we have to work around when designing "realtime" systems.
Realtime as "Fast Enough"
In software, realtime is not a literal concept but a perception. What we call "realtime" is just events happening fast enough that the delay is imperceptible.
For example, a messaging app feels realtime because:
- A user sends a message.
- The server receives it within milliseconds.
- The recipient sees the message pop up with no noticeable delay.
But under the hood, there are network packets, database writes, event queues, and UI updates happening in sequence. The illusion of realtime exists because these steps happen faster than the threshold where humans would notice.
Ordering Events in "Realtime"
If no two events happen at the same time, how do we determine which event came first when they occur nearly simultaneously? This problem becomes critical in distributed systems, where different nodes operate with slightly different clocks.
ULIDs: Unique and Sortable Event Identifiers
One elegant solution is the Universally Unique Lexicographically Sortable Identifier (ULID). Unlike traditional UUIDs (which are unique but not ordered), ULIDs encode a timestamp as the first part of the identifier. This allows events to be sorted chronologically without relying on external timestamps, which may be unreliable. We used ULIDs as the foundation of our event system at Letter to establish order within a distributed (banking) system. If an event arrived into a system, but contained a ULID that was before the last stored event, we knew something in the system had become misaligned - we then employed an automated "refeed" system that kicked off a retrieval of the last N events, which could then be stored in the correct sequence. Imagine the danger of incorrectly storing a WITHDRAWAL
event after a DEPOSIT
event.
Example: Generating a ULID in Node.js
import { ulid } from "ulid";
const event1 = ulid();
const event2 = ulid();
console.log(event1, event2); // Always ordered chronologically
Even if two events occur within the same millisecond, ULIDs ensure a predictable order, helping maintain a sense of sequence in distributed systems.
Emulating Realtime with WebSockets
Most "realtime" applications use WebSockets to push updates instantly between systems. Unlike traditional HTTP requests (which are pull-based), WebSockets keep an open connection, allowing data to flow bi-directionally in realtime.
Example: A Simple WebSocket Server in Node.js
import { WebSocketServer } from "ws";
const wss = new WebSocketServer({ port: 8080 });
wss.on("connection", (ws) => {
ws.send("Welcome to the realtime world!");
ws.on("message", (message) => console.log(`Received: ${message}`));
});
A client connects, the server sends an initial message, and the client can push data instantly. This enables chat apps, live notifications, and collaborative tools like Google Docs.
The "Realtime" Illusion: One System, Many Views
Consider a collaborative app where two users edit the same document. One user makes an edit, and the other sees it appear "instantly." What actually happens?
- User A modifies the document in their browser.
- The change is sent via WebSocket to the server.
- The server processes the update.
- The server pushes the update to User B's browser.
- User B's UI updates.
Each step takes time, but when executed within milliseconds, the illusion of simultaneity is maintained.
To enhance this illusion, developers use:
- Optimistic UI updates: Show changes instantly before confirmation from the server. Rollback if something goes wrong on the server, or the update was actually rejected.
- Latency compensation: Apply predicted changes before actual events arrive.
- Conflict resolution: Merge simultaneous edits without overwriting data.
Conclusion: Realtime Is Just Fast Sequential Events
At the core, "realtime" computing is about:
Ensuring a clear event order - (ULIDs, logical clocks)
Minimizing delay between events - (WebSockets, event-driven architectures)
Maintaining the illusion of simultaneity - (Optimistic UI, latency compensation)
The next time you use a chat app or a live dashboard, remember: nothing is actually happening "at the same time"—it's just a well-crafted sequence of events, happening faster than you can notice.
"The distinction between past, present, and future is only a stubbornly persistent illusion." - Albert Einstein