{"id":2735,"date":"2025-06-05T14:36:59","date_gmt":"2025-06-05T14:36:59","guid":{"rendered":"https:\/\/diznr.com\/?p=2735"},"modified":"2025-06-05T14:36:59","modified_gmt":"2025-06-05T14:36:59","slug":"vector-clock-in-distributed-system-clock-design-vector","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/vector-clock-in-distributed-system-clock-design-vector\/","title":{"rendered":"Vector Clock in Distributed System clock design vector."},"content":{"rendered":"<p>Vector Clock in Distributed System clock design vector.<\/p>\n<p>[fvplayer id=&#8221;88&#8243;]<\/p>\n<h3>\ud83d\udd39 <strong>Vector Clock in Distributed Systems \u2013 Clock Design &amp; Concept<\/strong><\/h3>\n<hr \/>\n<h3>\u2705 <strong>What is a Vector Clock?<\/strong><\/h3>\n<p>A <strong>Vector Clock<\/strong> is a <strong>logical clock mechanism<\/strong> used in <strong>distributed systems<\/strong> to capture <strong>causal relationships<\/strong> between events \u2014 especially to determine whether <strong>one event happened before another<\/strong> (\u2192 <strong>&#8220;happened-before&#8221; relation<\/strong>).<\/p>\n<p>Unlike <strong>Lamport clocks<\/strong> (which can only show if events are ordered or concurrent), <strong>vector clocks<\/strong> can precisely track <strong>causality<\/strong>.<\/p>\n<hr \/>\n<h3>\ud83e\udded <strong>Why is it Needed?<\/strong><\/h3>\n<p>In distributed systems, due to the absence of a global clock:<\/p>\n<ul>\n<li>It&#8217;s hard to know the actual order of events.<\/li>\n<li>Vector clocks help track <strong>causal dependencies<\/strong> among processes.<\/li>\n<\/ul>\n<hr \/>\n<h3>\ud83d\udcd0 <strong>Vector Clock Design (Structure)<\/strong><\/h3>\n<p>Each <strong>process<\/strong> in a distributed system maintains a <strong>vector of integers<\/strong> \u2014 one entry for every process in the system.<\/p>\n<h4>Example:<\/h4>\n<p>For a system with 3 processes <strong>P1, P2, P3<\/strong>, each process maintains a vector clock like:<\/p>\n<pre><code>VC(P1) = [v1, v2, v3]\n<\/code><\/pre>\n<p>Where:<\/p>\n<ul>\n<li><code>v1<\/code>: P1\u2019s own clock<\/li>\n<li><code>v2<\/code>: P1\u2019s knowledge of P2\u2019s clock<\/li>\n<li><code>v3<\/code>: P1\u2019s knowledge of P3\u2019s clock<\/li>\n<\/ul>\n<hr \/>\n<h3>\ud83d\udd27 <strong>How Vector Clocks Work (Rules):<\/strong><\/h3>\n<ol>\n<li><strong>Initialization:<\/strong>\n<ul>\n<li>Every process starts with vector <code>[0, 0, ..., 0]<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>Local Event:<\/strong>\n<ul>\n<li>A process increments its own clock.<\/li>\n<li><code>VC[i] = VC[i] + 1<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>Send Message:<\/strong>\n<ul>\n<li>Increment local clock.<\/li>\n<li>Send the <strong>entire vector<\/strong> along with the message.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Receive Message:<\/strong>\n<ul>\n<li>Increment own clock.<\/li>\n<li>Take the <strong>element-wise maximum<\/strong> of the received vector and own vector.<\/li>\n<\/ul>\n<pre><code>VC[i] = max(VC[i], received VC[i]) for all i\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>\ud83d\udcca <strong>Example:<\/strong><\/h3>\n<p>Let\u2019s assume:<\/p>\n<ul>\n<li><code>P1<\/code> sends a message to <code>P2<\/code><\/li>\n<li>VC(P1) before sending: <code>[2,0,0]<\/code><\/li>\n<li><code>P1<\/code> sends message \u2192 <code>[3,0,0]<\/code> to P2<\/li>\n<\/ul>\n<p><code>P2<\/code> receives message when its clock was <code>[1,2,0]<\/code><br \/>\nNow it computes:<\/p>\n<pre><code>VC(P2) = max([1,2,0], [3,0,0]) \u2192 [3,2,0]\nThen increments its own component \u2192 [3,3,0]\n<\/code><\/pre>\n<hr \/>\n<h3>\ud83e\udde0 <strong>Interpretation of Vector Clocks:<\/strong><\/h3>\n<p>For two events with vector clocks <code>VC1<\/code> and <code>VC2<\/code>:<\/p>\n<ul>\n<li><strong>VC1 &lt; VC2<\/strong> \u2192 VC1 happened before VC2<\/li>\n<li><strong>VC1 || VC2<\/strong> \u2192 Events are <strong>concurrent<\/strong> (no causal relationship)<\/li>\n<\/ul>\n<hr \/>\n<h3>\ud83d\udcdd <strong>Benefits of Vector Clocks:<\/strong><\/h3>\n<ul>\n<li>Captures <strong>causality<\/strong> precisely.<\/li>\n<li>Helps in <strong>version control<\/strong>, <strong>conflict resolution<\/strong>, and <strong>event ordering<\/strong>.<\/li>\n<li>Used in <strong>distributed databases<\/strong>, <strong>Git<\/strong>, <strong>blockchains<\/strong>, etc.<\/li>\n<\/ul>\n<hr \/>\n<h3>\u2696\ufe0f <strong>Limitations:<\/strong><\/h3>\n<ul>\n<li>Requires <strong>O(n)<\/strong> space and communication overhead (where <em>n<\/em> = number of processes).<\/li>\n<li>Not scalable for large systems.<\/li>\n<\/ul>\n<hr \/>\n<p>Would you like a <strong>diagram<\/strong>, <strong>visual animation<\/strong>, or <strong>real-world application (like in DynamoDB or Git)<\/strong>? I can also provide this in <strong>Hindi<\/strong> if you prefer.<\/p>\n<h3><a href=\"https:\/\/www.rcet.org.in\/uploads\/academics\/regulation2021\/rohini_45382112945.pdf\" target=\"_blank\" rel=\"noopener\">Vector Clock in Distributed System clock design vector.<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.jetir.org\/papers\/JETIR2105078.pdf\" target=\"_blank\" rel=\"noopener\">LOGICAL AND VECTOR CLOCKS USED IN &#8230;<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.cs.ubc.ca\/~bestchai\/teaching\/cs538b_2020w1\/slides\/vclocks.pdf\" target=\"_blank\" rel=\"noopener\">A Practical Tour of Vector Clock Systems.<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/profile.iiita.ac.in\/bibhas.ghoshal\/lecture_slides\/distributed\/Clock.pdf\" target=\"_blank\" rel=\"noopener\">Clocks in Distributed System<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.cs.uic.edu\/~ajayk\/Chapter3.pdf\" target=\"_blank\" rel=\"noopener\">Chapter 3: Logical Time<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Vector Clock in Distributed System clock design vector. [fvplayer id=&#8221;88&#8243;] \ud83d\udd39 Vector Clock in Distributed Systems \u2013 Clock Design &amp; Concept \u2705 What is a Vector Clock? A Vector Clock is a logical clock mechanism used in distributed systems to capture causal relationships between events \u2014 especially to determine whether one event happened before another [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[],"class_list":["post-2735","post","type-post","status-publish","format-standard","hentry","category-distributed-computing"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=2735"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2735\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=2735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=2735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=2735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}