How Google handles Leap Seconds

Vishal Kamath
5 min readDec 9, 2023

--

Be sure to leave a Clap if you enjoy 😊

How do we calculate a Seconds on Earth?

So there are generally two way we keep track of time.

  1. Solar Time: If we start our clocks when the sun is at its highest point in the sky, and we call it Noon (12 PM). The time it takes for the sun to go around and return back to its highest position is called a solar day. A day consists of 60 x 60 x 24 = 86,400 seconds so we calculate a solar second to be 1 / 86,400th of a solar day.
  2. TAI ( International Atomic Time ): TAI doesn’t rely on what happens in the sky but it is based on certain properties of atoms. The electrons of Cesium atom jump between two configuration more that 9 billion times per second. Scientist figured out exactly how many of those oscillations fit into a solar second, and defined that One second is the time it takes for the cesium frequency to oscillate 9,192,631,770 times. This second is called the SI second.
image from Hyperphysics

Why do Leap Seconds occur?

Since the Atomic time is based on a the constant properties of cesium atom and solar time is based on the rotation and revolution of the earth, they don’t always agree with each. When accounting for Earths rotations the real length of the day is somewhat unpredictable, There are some irregular factors that can slow down the rotation of the earth (Three Gorges Dam in China) and factors that speed up the rotation of the earth (The earthquakes in 2011).

To make up for the discrepancy between Atomic time and Solar Time every few years we add or subtract a second from the TAI and this is what we call a Leap Second. The International Earth Rotation and reference systems service announces these leap seconds and inserts them on June 30th or Dec 31st. When you factor in these leap second into the TAI you get the UTC ( Coordinated Universal Time ).

By UnaitxuGV, Heitordp and others — Outline based on the map by the U.S. Central Intelligence Agency (CIA).Time zone information based on the Time Zone Database by the Internet Assigned Numbers Authority (IANA), with the following differences:Mongolian provinces of Govi-Altai and Zavkhan in UTC+8[1][2][3][4][5]Abkhazia, South Ossetia and Russian-occupied territories of Ukraine in UTC+3[6][7][8], Public Domain, https://commons.wikimedia.org/w/index.php?curid=22556731

How do devices keep track of time?

Did you ever had a watch that ticks slower or faster than normal and you have to correct it every now and then with you cell phones clock. Devices run into the same issue as well and they need to be synchronized. For time synchronization your laptops, smart phone, desktops use a service called NTP (Network Time Protocol).

Photo by Oladimeji Ajegbile: https://www.pexels.com/photo/close-up-photo-of-teal-digital-clock-2397363/

NTP periodically checks the devices time against a more accurate server, which may be connected to an external source of time, such as an atomic clock. NTP also takes into consideration factors like how long the NTP server takes to reply, or the speed of the network between you and the server when setting a better time on the device you’re using.

Why does time matter at Google

source from Wikipedia

At Google, getting time right is super important. Everything that Google provides, like keeping data updated and showing search results in the right order, relies on accurate time.

Having a very large-scale distributed systems, like Googles, requires time to be well synchronized and most importantly, time should always move forward. Whenever a leap second occurs, computers factor them in by repeating a second by setting their clocks backwards a second.

But this “repeating” of a second can be a problem. What will happen to all the operations that run during that second? all the servers and systems that Google runs, what will happen to them?

Google services are designed for data integrity and reliability, these services refuse to work if their time is wrong. In 2005, Google noticed that a number of systems stopped working during the leap second. And so to fix this Issue the came with a solution called

Leap Smear

Google modified their NTP servers to gradually add a couple of milliseconds varying over a time window before the moment when the leap second actually happens. This meant that when it became time to add an extra second at midnight, Googles clocks had already taken this into account, by skewing the time over the course of an entire day. This meant so that time always moved forward.

Example of a Leap Smear

The last leap second occurred on 31st December 2016. The smear period will starts at 2016–12–31 12:00:00 UTC and continues through 2017–01–01 12:00:00 UTC. Before and after this period, smeared clocks and time service agree with clocks that apply leap seconds.

During the smear, clocks run slightly slower than usual. Each second of time in the smeared timescale is about 11.6 μs longer than an SI second.

At the beginning of the leap second, smeared time is just under 0.5 s behind UTC. UTC inserts an additional second, while smeared time continues uninterrupted. This causes smeared time to become just under 0.5 s ahead of UTC when the leap second ends.

By continuing to run the clocks at the same slowed rate, the ongoing smear reduces this offset over the next twelve hours. By 12:00:00, smeared and leaping clocks agree again.

Over the 86,401 SI seconds of the smear, the stretch in the 86,400 indicated seconds adds up to the one additional SI second required by the leap.

A negative leap second, if one were ever to occur, would be smeared by speeding up clocks over the 86,399 SI seconds from noon to noon.

--

--