{"id":2617,"date":"2025-06-07T11:53:50","date_gmt":"2025-06-07T11:53:50","guid":{"rendered":"https:\/\/diznr.com\/?p=2617"},"modified":"2025-06-07T11:53:50","modified_gmt":"2025-06-07T11:53:50","slug":"clock-synchronization-in-distributed-system-with-algorithm-and-example","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/clock-synchronization-in-distributed-system-with-algorithm-and-example\/","title":{"rendered":"Clock Synchronization in Distributed System With Algorithm and Example"},"content":{"rendered":"<p>Clock Synchronization in Distributed System With Algorithm and Example. In this lecture You will learn about the Clock and its working with different time zone in the Globe.<\/p>\n<p><span style=\"color: #ffffff\">Clock Synchronization in Distributed System With Algorithm And Example Clock Synchronization Algorithm Clock Synchronization Example Synchronization In Distributed Systems Clock Synchronization In Distributed System Berkeley Algorithm Clock Synchronization.<\/span><\/p>\n<p>[fvplayer id=&#8221;83&#8243;]<\/p>\n<p><span style=\"color: #ffffff\">Clock Synchronization Algorithms What Is Clock Synchronization In Distributed System Types Of Clock Synchronization In Distributed System Synchronization In Distributed Systems Video Lecture Clock Synchronization In Distributed System Video Logical Clock Synchronization In Distributed System.<\/span><\/p>\n<h3 data-start=\"0\" data-end=\"55\"><strong data-start=\"2\" data-end=\"53\">\u00a0Clock Synchronization in Distributed Systems<\/strong><\/h3>\n<p data-start=\"57\" data-end=\"305\">In <strong data-start=\"60\" data-end=\"83\">distributed systems<\/strong>, different machines (nodes) have their own clocks, which can drift due to hardware differences, network delays, or processing times. <strong data-start=\"217\" data-end=\"242\">Clock synchronization<\/strong> ensures that all nodes in the system agree on a common time.<\/p>\n<h3 data-start=\"312\" data-end=\"360\"><strong data-start=\"315\" data-end=\"358\">\u00a0Why is Clock Synchronization Needed?<\/strong><\/h3>\n<p data-start=\"361\" data-end=\"610\"><strong data-start=\"365\" data-end=\"394\">Ordering Events Correctly<\/strong> \u2013 Ensures event timestamps are consistent.<br data-start=\"437\" data-end=\"440\" \/><strong data-start=\"444\" data-end=\"474\">Preventing Inconsistencies<\/strong> \u2013 Avoids conflicts in databases and transactions.<br data-start=\"524\" data-end=\"527\" \/><strong data-start=\"531\" data-end=\"553\">Security &amp; Logging<\/strong> \u2013 Helps in fraud detection, debugging, and audit logs.<\/p>\n<p data-start=\"612\" data-end=\"668\"><strong data-start=\"615\" data-end=\"627\">Example:<\/strong><br data-start=\"627\" data-end=\"630\" \/>Imagine a bank&#8217;s distributed system:<\/p>\n<ul data-start=\"669\" data-end=\"854\">\n<li data-start=\"669\" data-end=\"720\"><strong data-start=\"671\" data-end=\"681\">Node A<\/strong> records a withdrawal at <strong data-start=\"706\" data-end=\"718\">12:30 PM<\/strong><\/li>\n<li data-start=\"721\" data-end=\"769\"><strong data-start=\"723\" data-end=\"733\">Node B<\/strong> records a deposit at <strong data-start=\"755\" data-end=\"767\">12:29 PM<\/strong><\/li>\n<li data-start=\"770\" data-end=\"854\">If clocks are not synchronized, the system may process transactions incorrectly.<\/li>\n<\/ul>\n<h3 data-start=\"861\" data-end=\"903\"><strong data-start=\"864\" data-end=\"901\">\u00a0Types of Clock Synchronization<\/strong><\/h3>\n<h3 data-start=\"905\" data-end=\"943\"><strong data-start=\"909\" data-end=\"941\">\u00a0External Synchronization<\/strong><\/h3>\n<ul data-start=\"944\" data-end=\"1132\">\n<li data-start=\"944\" data-end=\"1042\">Clocks are synchronized with an external <strong data-start=\"987\" data-end=\"1002\">time source<\/strong> like <strong data-start=\"1008\" data-end=\"1039\">NTP (Network Time Protocol)<\/strong>.<\/li>\n<li data-start=\"1043\" data-end=\"1132\">Used in real-world systems like <strong data-start=\"1077\" data-end=\"1095\">Google Spanner<\/strong> and <strong data-start=\"1100\" data-end=\"1129\">financial trading systems<\/strong>.<\/li>\n<\/ul>\n<h3 data-start=\"1134\" data-end=\"1172\"><strong data-start=\"1138\" data-end=\"1170\">\u00a0Internal Synchronization<\/strong><\/h3>\n<ul data-start=\"1173\" data-end=\"1302\">\n<li data-start=\"1173\" data-end=\"1302\">Clocks in all nodes of a distributed system are synchronized <strong data-start=\"1236\" data-end=\"1255\">with each other<\/strong> but not necessarily with an external source.<\/li>\n<\/ul>\n<h3 data-start=\"1309\" data-end=\"1353\"><strong data-start=\"1312\" data-end=\"1351\">\u00a0Clock Synchronization Algorithms<\/strong><\/h3>\n<h3 data-start=\"1355\" data-end=\"1409\"><strong data-start=\"1359\" data-end=\"1409\">\u00a0Cristian\u2019s Algorithm (Client-Server Model)<\/strong><\/h3>\n<p data-start=\"1410\" data-end=\"1558\">\u00a0Used when one machine has access to an <strong data-start=\"1451\" data-end=\"1475\">accurate time source<\/strong>.<br data-start=\"1476\" data-end=\"1479\" \/>\u00a0Works by <strong data-start=\"1490\" data-end=\"1528\">requesting time from a time server<\/strong> and adjusting local clocks.<\/p>\n<h4 data-start=\"1560\" data-end=\"1589\"><strong data-start=\"1565\" data-end=\"1587\">\u00a0Algorithm Steps<\/strong><\/h4>\n<ol data-start=\"1590\" data-end=\"1774\">\n<li data-start=\"1590\" data-end=\"1648\">A client sends a <strong data-start=\"1610\" data-end=\"1626\">time request<\/strong> to the time server.<\/li>\n<li data-start=\"1649\" data-end=\"1699\">The server replies with <strong data-start=\"1676\" data-end=\"1696\">its current time<\/strong>.<\/li>\n<li data-start=\"1700\" data-end=\"1774\">The client calculates the <strong data-start=\"1729\" data-end=\"1749\">round-trip delay<\/strong> and adjusts its clock.<\/li>\n<\/ol>\n<p data-start=\"1776\" data-end=\"1793\"><strong data-start=\"1779\" data-end=\"1791\">Example:<\/strong><\/p>\n<ul data-start=\"1794\" data-end=\"2052\">\n<li data-start=\"1794\" data-end=\"1839\">Client sends request at <strong data-start=\"1820\" data-end=\"1837\">T1 = 10:00:00<\/strong><\/li>\n<li data-start=\"1840\" data-end=\"1900\">Server receives request and replies at <strong data-start=\"1881\" data-end=\"1898\">T2 = 10:00:05<\/strong><\/li>\n<li data-start=\"1901\" data-end=\"1950\">Client receives response at <strong data-start=\"1931\" data-end=\"1948\">T3 = 10:00:08<\/strong><\/li>\n<li data-start=\"1951\" data-end=\"2052\">Estimated time = <span class=\"katex\"><span class=\"katex-mathml\">T2+(T3\u2212T1)2T2 + \\frac{(T3 &#8211; T1)}{2}<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">T<\/span><span class=\"mord\">2<\/span><span class=\"mbin\">+<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">2<\/span><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(<\/span><span class=\"mord mathnormal mtight\">T<\/span>3<span class=\"mbin mtight\">\u2212<\/span><span class=\"mord mathnormal mtight\">T<\/span>1<span class=\"mclose mtight\">)<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> = <span class=\"katex\"><span class=\"katex-mathml\">10:00:05+(8\u22120)210:00:05 + \\frac{(8-0)}{2}<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord\">10<\/span><span class=\"mrel\">:<\/span><\/span><span class=\"base\"><span class=\"mord\">00<\/span><span class=\"mrel\">:<\/span><\/span><span class=\"base\"><span class=\"mord\">05<\/span><span class=\"mbin\">+<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">2<\/span><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(<\/span>8<span class=\"mbin mtight\">\u2212<\/span>0<span class=\"mclose mtight\">)<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> = <strong data-start=\"2038\" data-end=\"2050\">10:00:09<\/strong><\/li>\n<\/ul>\n<p data-start=\"2054\" data-end=\"2111\"><strong data-start=\"2057\" data-end=\"2072\">Limitation:<\/strong> Network delays can introduce errors.<\/p>\n<h3 data-start=\"2118\" data-end=\"2173\"><strong data-start=\"2122\" data-end=\"2171\">\u00a0Berkeley\u2019s Algorithm (Master-Slave Model)<\/strong><\/h3>\n<p data-start=\"2174\" data-end=\"2315\">\u00a0Used in systems where <strong data-start=\"2198\" data-end=\"2238\">no external time source is available<\/strong>.<br data-start=\"2239\" data-end=\"2242\" \/>\u00a0A <strong data-start=\"2246\" data-end=\"2261\">master node<\/strong> calculates an <strong data-start=\"2276\" data-end=\"2298\">average clock time<\/strong> for all nodes.<\/p>\n<h4 data-start=\"2317\" data-end=\"2346\"><strong data-start=\"2322\" data-end=\"2344\">\u00a0Algorithm Steps<\/strong><\/h4>\n<ol data-start=\"2347\" data-end=\"2539\">\n<li data-start=\"2347\" data-end=\"2411\">The <strong data-start=\"2354\" data-end=\"2369\">master node<\/strong> polls all nodes for their current time.<\/li>\n<li data-start=\"2412\" data-end=\"2471\">It calculates the <strong data-start=\"2433\" data-end=\"2449\">average time<\/strong>, ignoring outliers.<\/li>\n<li data-start=\"2472\" data-end=\"2539\">The master instructs nodes to adjust their clocks accordingly.<\/li>\n<\/ol>\n<p data-start=\"2541\" data-end=\"2558\"><strong data-start=\"2544\" data-end=\"2556\">Example:<\/strong><\/p>\n<div class=\"overflow-x-auto contain-inline-size\">\n<table data-start=\"2559\" data-end=\"2815\">\n<thead data-start=\"2559\" data-end=\"2609\">\n<tr data-start=\"2559\" data-end=\"2609\">\n<th data-start=\"2559\" data-end=\"2566\">Node<\/th>\n<th data-start=\"2566\" data-end=\"2582\">Reported Time<\/th>\n<th data-start=\"2582\" data-end=\"2595\">Difference<\/th>\n<th data-start=\"2595\" data-end=\"2609\">Adjustment<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2660\" data-end=\"2815\">\n<tr data-start=\"2660\" data-end=\"2709\">\n<td>A<\/td>\n<td>10:00:05<\/td>\n<td>-3 sec<\/td>\n<td>Add 3 sec<\/td>\n<\/tr>\n<tr data-start=\"2710\" data-end=\"2763\">\n<td>B<\/td>\n<td>10:00:10<\/td>\n<td>+2 sec<\/td>\n<td>Subtract 2 sec<\/td>\n<\/tr>\n<tr data-start=\"2764\" data-end=\"2815\">\n<td>C (Master)<\/td>\n<td>10:00:08<\/td>\n<td>0 sec<\/td>\n<td>No change<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p data-start=\"2817\" data-end=\"2875\"><strong data-start=\"2820\" data-end=\"2835\">Limitation:<\/strong> Assumes <strong data-start=\"2844\" data-end=\"2872\">master clock is accurate<\/strong>.<\/p>\n<h3 data-start=\"2882\" data-end=\"2948\"><strong data-start=\"2886\" data-end=\"2946\">\u00a0Lamport Timestamps (Logical Clock, No Physical Time)<\/strong><\/h3>\n<p data-start=\"2949\" data-end=\"3027\">\u00a0Used in <strong data-start=\"2959\" data-end=\"2977\">event ordering<\/strong> when precise time synchronization is difficult.<\/p>\n<h4 data-start=\"3029\" data-end=\"3058\"><strong data-start=\"3034\" data-end=\"3056\">\u00a0Algorithm Steps<\/strong><\/h4>\n<ol data-start=\"3059\" data-end=\"3273\">\n<li data-start=\"3059\" data-end=\"3107\">Each process maintains a <strong data-start=\"3087\" data-end=\"3104\">logical clock<\/strong>.<\/li>\n<li data-start=\"3108\" data-end=\"3154\">Every event increments the logical clock.<\/li>\n<li data-start=\"3155\" data-end=\"3273\">If <strong data-start=\"3161\" data-end=\"3174\">Process A<\/strong> sends a message to <strong data-start=\"3194\" data-end=\"3207\">Process B<\/strong>, B sets its logical clock to <strong data-start=\"3237\" data-end=\"3270\">max(A\u2019s clock, B\u2019s clock) + 1<\/strong>.<\/li>\n<\/ol>\n<p data-start=\"3275\" data-end=\"3292\"><strong data-start=\"3278\" data-end=\"3290\">Example:<\/strong><\/p>\n<div class=\"overflow-x-auto contain-inline-size\">\n<table data-start=\"3293\" data-end=\"3491\">\n<thead data-start=\"3293\" data-end=\"3339\">\n<tr data-start=\"3293\" data-end=\"3339\">\n<th data-start=\"3293\" data-end=\"3302\">Event<\/th>\n<th data-start=\"3302\" data-end=\"3314\">Process A<\/th>\n<th data-start=\"3314\" data-end=\"3326\">Process B<\/th>\n<th data-start=\"3326\" data-end=\"3339\">Process C<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"3384\" data-end=\"3491\">\n<tr data-start=\"3384\" data-end=\"3427\">\n<td>Start<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr data-start=\"3428\" data-end=\"3460\">\n<td>A sends msg to B<\/td>\n<td>2<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr data-start=\"3461\" data-end=\"3491\">\n<td>B receives msg<\/td>\n<td>&#8211;<\/td>\n<td>3<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p data-start=\"3493\" data-end=\"3578\"><strong data-start=\"3496\" data-end=\"3511\">Limitation:<\/strong> Only provides event ordering, not absolute time synchronization.<\/p>\n<h3 data-start=\"3585\" data-end=\"3620\"><strong data-start=\"3588\" data-end=\"3618\">\u00a0Which Algorithm to Use?<\/strong><\/h3>\n<p data-start=\"3621\" data-end=\"3829\"><strong data-start=\"3623\" data-end=\"3700\">If an external time source is available \u2192 Use NTP or Cristian\u2019s Algorithm<\/strong><br data-start=\"3700\" data-end=\"3703\" \/><strong data-start=\"3705\" data-end=\"3762\">If no external time source \u2192 Use Berkeley\u2019s Algorithm<\/strong><br data-start=\"3762\" data-end=\"3765\" \/><strong data-start=\"3767\" data-end=\"3827\">If ordering events is important \u2192 Use Lamport Timestamps<\/strong><\/p>\n<h3 data-start=\"3836\" data-end=\"3862\"><strong data-start=\"3839\" data-end=\"3860\">\u00a0Final Thoughts<\/strong><\/h3>\n<p data-start=\"3863\" data-end=\"4087\">Clock synchronization is <strong data-start=\"3888\" data-end=\"3899\">crucial<\/strong> in distributed systems for <strong data-start=\"3927\" data-end=\"3978\">data consistency, event ordering, and security.<\/strong> The choice of algorithm depends on <strong data-start=\"4014\" data-end=\"4084\">network conditions, system architecture, and accuracy requirements<\/strong>.<\/p>\n<p data-start=\"4089\" data-end=\"4175\" data-is-last-node=\"\" data-is-only-node=\"\">\u00a0<strong data-start=\"4092\" data-end=\"4175\" data-is-last-node=\"\">Want a real-world implementation of these algorithms in Python? Let me know!<\/strong><\/p>\n<h3 data-start=\"4089\" data-end=\"4175\"><a href=\"https:\/\/people.cs.rutgers.edu\/~pxk\/417\/notes\/content\/05-clock-synchronization-slides.pdf\" target=\"_blank\" rel=\"noopener\">Clock Synchronization in Distributed System With Algorithm and Example<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/econtent.in\/pacc.in\/admin\/contents\/71_MCS3_2020112309553977.pdf\" target=\"_blank\" rel=\"noopener\">distributed os- unit 3 clock synchronization &#8211; econtent.in<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/www.irjet.net\/archives\/V9\/i3\/IRJET-V9I3350.pdf\" target=\"_blank\" rel=\"noopener\">Clock Synchronization in Distributed Systems<\/a><\/h3>\n<p data-start=\"0\" data-end=\"205\">Certainly! Here&#8217;s a clear and concise explanation of <strong data-start=\"53\" data-end=\"101\">Clock Synchronization in Distributed Systems<\/strong>, along with <strong data-start=\"114\" data-end=\"141\">algorithms and examples<\/strong> \u2013 very useful for understanding distributed computing concepts.<\/p>\n<hr data-start=\"207\" data-end=\"210\" \/>\n<h2 data-start=\"212\" data-end=\"266\">\ud83d\udd52 <strong data-start=\"218\" data-end=\"266\">Clock Synchronization in Distributed Systems<\/strong><\/h2>\n<p data-start=\"268\" data-end=\"490\">In <strong data-start=\"271\" data-end=\"294\">distributed systems<\/strong>, each machine has its <strong data-start=\"317\" data-end=\"336\">own local clock<\/strong>, which may <strong data-start=\"348\" data-end=\"357\">drift<\/strong> due to hardware differences. To coordinate actions (e.g., logging, transactions, scheduling), <strong data-start=\"452\" data-end=\"477\">clock synchronization<\/strong> is required.<\/p>\n<hr data-start=\"492\" data-end=\"495\" \/>\n<h2 data-start=\"497\" data-end=\"529\">\u2705 <strong data-start=\"502\" data-end=\"529\">Why Synchronize Clocks?<\/strong><\/h2>\n<ul data-start=\"530\" data-end=\"669\">\n<li data-start=\"530\" data-end=\"573\">\n<p data-start=\"532\" data-end=\"573\">To maintain <strong data-start=\"544\" data-end=\"573\">consistency in timestamps<\/strong><\/p>\n<\/li>\n<li data-start=\"574\" data-end=\"618\">\n<p data-start=\"576\" data-end=\"618\">To prevent <strong data-start=\"587\" data-end=\"618\">anomalies in event ordering<\/strong><\/p>\n<\/li>\n<li data-start=\"619\" data-end=\"669\">\n<p data-start=\"621\" data-end=\"669\">Required for <strong data-start=\"634\" data-end=\"669\">coordinated actions and logging<\/strong><\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"671\" data-end=\"674\" \/>\n<h2 data-start=\"676\" data-end=\"701\">\ud83d\udcd8 <strong data-start=\"682\" data-end=\"701\">Types of Clocks<\/strong><\/h2>\n<ul data-start=\"702\" data-end=\"886\">\n<li data-start=\"702\" data-end=\"766\">\n<p data-start=\"704\" data-end=\"766\"><strong data-start=\"704\" data-end=\"723\">Hardware Clocks<\/strong>: Crystal oscillator-based (drift possible)<\/p>\n<\/li>\n<li data-start=\"767\" data-end=\"829\">\n<p data-start=\"769\" data-end=\"829\"><strong data-start=\"769\" data-end=\"787\">Logical Clocks<\/strong>: Event-based timestamps (Lamport, Vector)<\/p>\n<\/li>\n<li data-start=\"830\" data-end=\"886\">\n<p data-start=\"832\" data-end=\"886\"><strong data-start=\"832\" data-end=\"855\">Synchronized Clocks<\/strong>: Use algorithms to adjust time<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"888\" data-end=\"891\" \/>\n<h2 data-start=\"893\" data-end=\"943\">\u2699\ufe0f <strong data-start=\"899\" data-end=\"943\">Popular Clock Synchronization Algorithms<\/strong><\/h2>\n<hr data-start=\"945\" data-end=\"948\" \/>\n<h3 data-start=\"950\" data-end=\"1009\">1\ufe0f\u20e3 <strong data-start=\"958\" data-end=\"1009\">Cristian&#8217;s Algorithm (External Synchronization)<\/strong><\/h3>\n<p data-start=\"1011\" data-end=\"1057\"><strong data-start=\"1011\" data-end=\"1020\">Goal:<\/strong> Sync client time with a time server.<\/p>\n<p data-start=\"1059\" data-end=\"1069\"><strong data-start=\"1059\" data-end=\"1069\">Steps:<\/strong><\/p>\n<ol data-start=\"1070\" data-end=\"1282\">\n<li data-start=\"1070\" data-end=\"1124\">\n<p data-start=\"1073\" data-end=\"1124\">Client sends a time request to the <strong data-start=\"1108\" data-end=\"1123\">Time Server<\/strong>.<\/p>\n<\/li>\n<li data-start=\"1125\" data-end=\"1174\">\n<p data-start=\"1128\" data-end=\"1174\">Time Server replies with its current time <code data-start=\"1170\" data-end=\"1173\">T<\/code>.<\/p>\n<\/li>\n<li data-start=\"1175\" data-end=\"1282\">\n<p data-start=\"1178\" data-end=\"1209\">Client adjusts its clock using:<\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">Tclient=T+(Tround\u00a0trip)2T_{\\text{client}} = T + \\frac{(T_{\\text{round trip}})}{2}<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord\"><span class=\"mord mathnormal\">T<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\">client<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mord mathnormal\">T<\/span><span class=\"mbin\">+<\/span><\/span><span class=\"base\"><span class=\"mord\"><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\">2<span class=\"mopen\">(<\/span><span class=\"mord mathnormal\">T<\/span><span class=\"msupsub\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\">round\u00a0trip<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"mclose\">)<\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/li>\n<\/ol>\n<p data-start=\"1284\" data-end=\"1296\"><strong data-start=\"1284\" data-end=\"1296\">Example:<\/strong><\/p>\n<ul data-start=\"1297\" data-end=\"1417\">\n<li data-start=\"1297\" data-end=\"1327\">\n<p data-start=\"1299\" data-end=\"1327\">Client sends at 10:00:00.000<\/p>\n<\/li>\n<li data-start=\"1328\" data-end=\"1362\">\n<p data-start=\"1330\" data-end=\"1362\">Server replies with 10:00:10.000<\/p>\n<\/li>\n<li data-start=\"1363\" data-end=\"1383\">\n<p data-start=\"1365\" data-end=\"1383\">Round Trip = 100ms<\/p>\n<\/li>\n<li data-start=\"1384\" data-end=\"1417\">\n<p data-start=\"1386\" data-end=\"1417\">Client sets time = 10:00:10.050<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1419\" data-end=\"1458\"><strong data-start=\"1419\" data-end=\"1430\">Assumes<\/strong>: Symmetrical network delays<\/p>\n<hr data-start=\"1460\" data-end=\"1463\" \/>\n<h3 data-start=\"1465\" data-end=\"1524\">2\ufe0f\u20e3 <strong data-start=\"1473\" data-end=\"1524\">Berkeley\u2019s Algorithm (Internal Synchronization)<\/strong><\/h3>\n<p data-start=\"1526\" data-end=\"1603\"><strong data-start=\"1526\" data-end=\"1535\">Goal:<\/strong> Synchronize all nodes to an average time (no external time server).<\/p>\n<p data-start=\"1605\" data-end=\"1615\"><strong data-start=\"1605\" data-end=\"1615\">Steps:<\/strong><\/p>\n<ol data-start=\"1616\" data-end=\"1783\">\n<li data-start=\"1616\" data-end=\"1672\">\n<p data-start=\"1619\" data-end=\"1672\">A master node polls all nodes for their current time.<\/p>\n<\/li>\n<li data-start=\"1673\" data-end=\"1721\">\n<p data-start=\"1676\" data-end=\"1721\">Computes <strong data-start=\"1685\" data-end=\"1701\">average time<\/strong> (ignores outliers).<\/p>\n<\/li>\n<li data-start=\"1722\" data-end=\"1783\">\n<p data-start=\"1725\" data-end=\"1783\">Sends <strong data-start=\"1731\" data-end=\"1746\">adjustments<\/strong> to each node to sync to the average.<\/p>\n<\/li>\n<\/ol>\n<p data-start=\"1785\" data-end=\"1797\"><strong data-start=\"1785\" data-end=\"1797\">Example:<\/strong><\/p>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"1799\" data-end=\"1898\">\n<thead data-start=\"1799\" data-end=\"1818\">\n<tr data-start=\"1799\" data-end=\"1818\">\n<th data-start=\"1799\" data-end=\"1806\" data-col-size=\"sm\">Node<\/th>\n<th data-start=\"1806\" data-end=\"1818\" data-col-size=\"sm\">Time<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"1839\" data-end=\"1898\">\n<tr data-start=\"1839\" data-end=\"1858\">\n<td data-start=\"1839\" data-end=\"1846\" data-col-size=\"sm\">A<\/td>\n<td data-col-size=\"sm\" data-start=\"1846\" data-end=\"1858\">10:00:00<\/td>\n<\/tr>\n<tr data-start=\"1859\" data-end=\"1878\">\n<td data-start=\"1859\" data-end=\"1866\" data-col-size=\"sm\">B<\/td>\n<td data-col-size=\"sm\" data-start=\"1866\" data-end=\"1878\">10:00:10<\/td>\n<\/tr>\n<tr data-start=\"1879\" data-end=\"1898\">\n<td data-start=\"1879\" data-end=\"1886\" data-col-size=\"sm\">C<\/td>\n<td data-col-size=\"sm\" data-start=\"1886\" data-end=\"1898\">09:59:50<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"1900\" data-end=\"1924\"><strong data-start=\"1900\" data-end=\"1913\">Average =<\/strong> 10:00:00<\/p>\n<ul data-start=\"1925\" data-end=\"1980\">\n<li data-start=\"1925\" data-end=\"1941\">\n<p data-start=\"1927\" data-end=\"1941\">A stays same<\/p>\n<\/li>\n<li data-start=\"1942\" data-end=\"1964\">\n<p data-start=\"1944\" data-end=\"1964\">B subtracts 10 sec<\/p>\n<\/li>\n<li data-start=\"1965\" data-end=\"1980\">\n<p data-start=\"1967\" data-end=\"1980\">C adds 10 sec<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1982\" data-end=\"1985\" \/>\n<h3 data-start=\"1987\" data-end=\"2033\">3\ufe0f\u20e3 <strong data-start=\"1995\" data-end=\"2033\">Lamport Timestamps (Logical Clock)<\/strong><\/h3>\n<p data-start=\"2035\" data-end=\"2096\"><strong data-start=\"2035\" data-end=\"2044\">Goal:<\/strong> Maintain <strong data-start=\"2054\" data-end=\"2070\">causal order<\/strong> of events, not real-time.<\/p>\n<p data-start=\"2098\" data-end=\"2108\"><strong data-start=\"2098\" data-end=\"2108\">Rules:<\/strong><\/p>\n<ol data-start=\"2109\" data-end=\"2303\">\n<li data-start=\"2109\" data-end=\"2146\">\n<p data-start=\"2112\" data-end=\"2146\">Increment clock before each event.<\/p>\n<\/li>\n<li data-start=\"2147\" data-end=\"2186\">\n<p data-start=\"2150\" data-end=\"2186\">On message send, send current clock.<\/p>\n<\/li>\n<li data-start=\"2187\" data-end=\"2303\">\n<p data-start=\"2190\" data-end=\"2217\">On message receive, update:<\/p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\">Creceiver=max\u2061(Creceiver,Csender)+1C_{\\text{receiver}} = \\max(C_{\\text{receiver}}, C_{\\text{sender}}) + 1<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord\"><span class=\"mord mathnormal\">C<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\">receiver<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><span class=\"mrel\">=<\/span><\/span><span class=\"base\"><span class=\"mop\">max<\/span><span class=\"mopen\">(<\/span><span class=\"mord\"><span class=\"mord mathnormal\">C<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\">receiver<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><span class=\"mpunct\">,<\/span><span class=\"mord\"><span class=\"mord mathnormal\">C<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\"><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\">sender<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><\/span><\/span><\/span><span class=\"mclose\">)<\/span><span class=\"mbin\">+<\/span><\/span><span class=\"base\"><span class=\"mord\">1<\/span><\/span><\/span><\/span><\/span><\/li>\n<\/ol>\n<p data-start=\"2305\" data-end=\"2317\"><strong data-start=\"2305\" data-end=\"2317\">Example:<\/strong><\/p>\n<ul data-start=\"2318\" data-end=\"2391\">\n<li data-start=\"2318\" data-end=\"2343\">\n<p data-start=\"2320\" data-end=\"2343\">P1 sends message at T=3<\/p>\n<\/li>\n<li data-start=\"2344\" data-end=\"2391\">\n<p data-start=\"2346\" data-end=\"2391\">P2 receives and updates T = max(2, 3) + 1 = 4<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2393\" data-end=\"2437\">Maintains <strong data-start=\"2403\" data-end=\"2423\">\u201chappens-before\u201d<\/strong> relationship.<\/p>\n<hr data-start=\"2439\" data-end=\"2442\" \/>\n<h2 data-start=\"2444\" data-end=\"2464\">\ud83e\udde0 <strong data-start=\"2450\" data-end=\"2464\">Key Points<\/strong><\/h2>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"2466\" data-end=\"2829\">\n<thead data-start=\"2466\" data-end=\"2537\">\n<tr data-start=\"2466\" data-end=\"2537\">\n<th data-start=\"2466\" data-end=\"2486\" data-col-size=\"sm\">Algorithm<\/th>\n<th data-start=\"2486\" data-end=\"2500\" data-col-size=\"sm\">Sync Type<\/th>\n<th data-start=\"2500\" data-end=\"2512\" data-col-size=\"sm\">Real Time<\/th>\n<th data-start=\"2512\" data-end=\"2537\" data-col-size=\"sm\">Use Case<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2610\" data-end=\"2829\">\n<tr data-start=\"2610\" data-end=\"2684\">\n<td data-start=\"2610\" data-end=\"2630\" data-col-size=\"sm\">Cristian\u2019s<\/td>\n<td data-col-size=\"sm\" data-start=\"2630\" data-end=\"2644\">External<\/td>\n<td data-col-size=\"sm\" data-start=\"2644\" data-end=\"2655\">\u2705<\/td>\n<td data-col-size=\"sm\" data-start=\"2655\" data-end=\"2684\">Accurate time from server<\/td>\n<\/tr>\n<tr data-start=\"2685\" data-end=\"2757\">\n<td data-start=\"2685\" data-end=\"2705\" data-col-size=\"sm\">Berkeley\u2019s<\/td>\n<td data-col-size=\"sm\" data-start=\"2705\" data-end=\"2719\">Internal<\/td>\n<td data-col-size=\"sm\" data-start=\"2719\" data-end=\"2731\">Approx<\/td>\n<td data-col-size=\"sm\" data-start=\"2731\" data-end=\"2757\">Peer-to-peer networks<\/td>\n<\/tr>\n<tr data-start=\"2758\" data-end=\"2829\">\n<td data-start=\"2758\" data-end=\"2778\" data-col-size=\"sm\">Lamport Timestamp<\/td>\n<td data-col-size=\"sm\" data-start=\"2778\" data-end=\"2792\">Logical<\/td>\n<td data-col-size=\"sm\" data-start=\"2792\" data-end=\"2803\">\u274c<\/td>\n<td data-col-size=\"sm\" data-start=\"2803\" data-end=\"2829\">Event ordering<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"2831\" data-end=\"2834\" \/>\n<h2 data-start=\"2836\" data-end=\"2862\">\ud83d\udccc <strong data-start=\"2842\" data-end=\"2862\">Real World Usage<\/strong><\/h2>\n<ul data-start=\"2863\" data-end=\"3032\">\n<li data-start=\"2863\" data-end=\"2949\">\n<p data-start=\"2865\" data-end=\"2949\"><strong data-start=\"2865\" data-end=\"2896\">NTP (Network Time Protocol)<\/strong> \u2013 Uses hierarchical servers to sync clocks globally.<\/p>\n<\/li>\n<li data-start=\"2950\" data-end=\"3032\">\n<p data-start=\"2952\" data-end=\"3032\"><strong data-start=\"2952\" data-end=\"2970\">Google Spanner<\/strong> \u2013 Uses TrueTime API with GPS + atomic clocks for consistency.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"3034\" data-end=\"3037\" \/>\n<h2 data-start=\"3039\" data-end=\"3054\">\u2705 Conclusion<\/h2>\n<p data-start=\"3056\" data-end=\"3251\">Clock synchronization ensures consistency, coordination, and correctness in distributed systems. Depending on the <strong data-start=\"3170\" data-end=\"3222\">requirements (real-time accuracy or event order)<\/strong>, choose the right algorithm.<\/p>\n<hr data-start=\"3253\" data-end=\"3256\" \/>\n<p data-start=\"3258\" data-end=\"3352\" data-is-last-node=\"\" data-is-only-node=\"\">Would you like a <strong data-start=\"3275\" data-end=\"3286\">diagram<\/strong>, <strong data-start=\"3288\" data-end=\"3301\">flowchart<\/strong>, or <strong data-start=\"3306\" data-end=\"3323\">MCQ worksheet<\/strong> to revise this topic better?<\/p>\n<h3 data-start=\"3258\" data-end=\"3352\"><a href=\"https:\/\/www.ripublication.com\/acst17\/acstv10n6_38.pdf\" target=\"_blank\" rel=\"noopener\">Clock Synchronization in Distributed System With Algorithm and Example<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/people.cs.rutgers.edu\/~pxk\/rutgers\/notes\/content\/09-clock-synchronization-slides.pdf\" target=\"_blank\" rel=\"noopener\">Clock Synchronization &#8211; Distributed Systems<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/homes.cs.washington.edu\/~arvind\/cs425\/lectureNotes\/clocks-2.pdf\" target=\"_blank\" rel=\"noopener\">Logical Clocks Clock Synchronization<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Clock Synchronization in Distributed System With Algorithm and Example.Clock Synchronization in Distributed System With Algorithm And Example Clock Synchronization Algorithm Clock Synchronization Example Synchronization In Distributed Systems Clock Synchronization In Distributed System Berkeley Algorithm Clock Synchronization.<\/p>\n","protected":false},"author":64,"featured_media":2618,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[2078,2079,2080,2081,2082,2083,2084,2085,2086,2087,2088,2089],"class_list":["post-2617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-distributed-computing","tag-berkeley-algorithm-clock-synchronization","tag-clock-synchronization-algorithm","tag-clock-synchronization-algorithms","tag-clock-synchronization-example","tag-clock-synchronization-in-distribured-system-with-algorithm-and-example","tag-clock-synchronization-in-distributed-system","tag-clock-synchronization-in-distributed-system-video","tag-logical-clock-synchronization-in-distributed-system","tag-synchronization-in-distributed-systems","tag-synchronization-in-distributed-systems-video-lecture","tag-types-of-clock-synchronization-in-distributed-system","tag-what-is-clock-synchronization-in-distributed-system"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2617","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\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=2617"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2617\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media\/2618"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=2617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=2617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=2617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}