LearnViz CompSci
Home / Learn / Distributed Systems & Cloud / Logical Clocks

Intermediate Topic 20 of 51 Distributed Systems & Cloud

Logical Clocks

Lamport and vector clocks ordering events without wall time.

How it works

Logical clocks order events in a distributed system without relying on physical time. Lamport clocks keep a counter at each process, increment it on each event and set it to the maximum of local and received timestamps plus one on receipt, ensuring that if event a happens before b, then timestamp(a) is less than timestamp(b), though the reverse does not hold. Vector clocks keep a counter per process and can detect whether events are causally ordered or concurrent. Hybrid logical clocks combine physical time with logical counters.

Where it is used

Distributed databases such as Dynamo and Riak, conflict detection in replicated data, debugging and tracing, and causally consistent messaging use logical clocks.

Common pitfall

Vector clocks grow with the number of processes, which is costly for large systems, requiring pruning or dotted version vectors. Lamport timestamps cannot tell concurrent events apart. Comparing timestamps incorrectly leads to wrong conflict resolution. Define clearly what ordering the application needs and break ties consistently using process IDs.

Where it fits in the course

Logical Clocks is topic 20 of 51 in Distributed Systems & Cloud, rated Intermediate. It follows Clock Synchronization. The next topic is Consensus Problem.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Distributed Systems & Cloud quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Logical Clocks?
Lamport and vector clocks ordering events without wall time. It belongs to Distributed Systems & Cloud and is an intermediate-level topic.
Where do people use Logical Clocks?
Distributed databases such as Dynamo and Riak, conflict detection in replicated data, debugging and tracing, and causally consistent messaging use logical clocks.
What is the most common mistake with Logical Clocks?
Vector clocks grow with the number of processes, which is costly for large systems, requiring pruning or dotted version vectors.
What should I learn before this topic?
Start with Clock Synchronization, the topic just before it in Distributed Systems & Cloud.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Distributed Systems & Cloud quiz.
Is Logical Clocks hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Logical Clocks?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Logical Clocks?
Clock Synchronization, Consensus Problem, Consistency Models are closely connected. The full list is in the related topics section of this page.
What should I study after Logical Clocks?
Continue with Consensus Problem, the next topic in Distributed Systems & Cloud.

Related topics