Filip Troníček

A passionate maniac who loves modern web technologies, advocating for a better world with OSS. Your friendly neighborhood Open VSX man.


All the time(ly) matters

Published Dec 04, 2020

Hi folks, it’s me here again. Today I want to focus on an OSS product I launched in mid-December 2020, CountDowner. It is a really simple service for, well, counting down to dates. It was so simple to code in fact, that it took me about 2 hours to get it entirely working and ready to be published (most work is done in dd926c7). This year, I wanted to focus on making it a more usable and sustainable from the developer side. First, I needed to redesign the create page, which I did with js-datepicker and the native time-picker component. I also rewrote the code to use Webpack, because it should be faster and easier to integrate new libraries.

Synchronizing time and the impossibility of it

In CountDowner#14, I introduced a function that would synchronize the time with the help of a serverless function, which would just return the current UNIX timestamp and (if provided) the difference between the current and the provided timestamp. I chose Cloudflare workers for this because Vercel had too big of a ping - most of the time 200+ ms, which is not acceptable when working with time. The problem is, that the ping was still sometimes 50+ ms and I needed to account for that. You can easily subtract the ping from the difference, but that would also account for the ping back, which we don’t care about. In my implementation, we just assume that the round trip takes the same time to the server and back, so I just divide the ping by 2 and subtract that. If there was a better way, I would implement it, but it just cannot be done. There is a great article about this by twisted oak about this and why it mostly doesn’t matter anyway.

Diagram of the Cloudflare worker