What I learned from automating millions of web site deploys
Tags: webdev, serverless, edge, jamstack
Published: 2022-09-26 11:53:05

---
title: What I learned from automating millions of web site deploys
published: true
description: Lessons learned from millions of automated deployment over 4 years, and how Edge Functions can help.
tags: [webdev, Serverless, "Edge", Jamstack]
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3dthidilc9l2gfi6lh6p.png
# Use a ratio of 100:42 for best results.
---

Back in 2018 [I decided to demonstrate](https://twitter.com/philhawksworth/status/1020292946892152832) how it had become feasible to automate the deployment of a web site thanks to modern web tooling and hosting services. I had been immersed in the world of enterprise web projects where deployments involved code and content freezes, a deployment team, holding your breath, and hoping for the best. the idea was triggered by this throw-away tweet from [Zach Leatherman](https://twitter.com/zachleat/).

> Free side project idea: HTML-only static site generated clock that deploys a new version to [@netlify](https://twitter.com/netlify) every minute
— [Zach Leatherman](https://twitter.com/zachleat/status/1020034115817680896)


So I made [setyourwatchby.netlify.app](https://setyourwatchby.netlify.app), a site which displayed the time. No client-side JavaScript to get the correct time for each visitor, just HTML containing the time that the site was generated as part of an automated build and deployment (and localised pages served up thanks to some [CDN routing](https://docs.netlify.com/routing/redirects/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch)).


I've [described this in some detail in the past](https://www.netlify.com/blog/2018/08/02/exploring-the-potential-of-friction-free-deployments/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch), but let's move along.

The point I was making was that the friction and risk in deploying updates to a site had been so dramatically reduced, that it was now safe to perform unattended deployments automatically every single minute of the day.

From 2018 to 2022 the site has been automatically rebuilt and redeployed millions of times.


## Time and technology moves on

As my *millions* of site deploy logs on Netlify will illustrate, time moves on. Reliable build automation has become readily available for developers, even in the enterprise space. But deploying every minute is silly, really. It's fine for making a point as part of a demo, but we can be far more efficient and responsible than that.


![The Netlify deploy screen showing a list of many deployments ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awr5xxuooxul6p1wfkps.png)


I needed to retire the demo site, but also wanted to make sure that you, dear reader, still had a way to tell the time! [setyourwatchby.netlify.app](https://setyourwatchby.netlify.app) still had to function even after I turned off the scheduled builds.

## Edge Functions to the rescue

The arrival of Edge Functions saved the day. [Netlify's Edge Functions](https://www.netlify.com/products/#netlify-edge-functions) are a low latency serverless runtime which can handle HTTP requests at locations close to the user and modify the HTTP response being returned. They provide a way to dynamically service every HTTP request without the need to manage and maintain a server. They're JavaScript, so I could just write [a single function](https://github.com/philhawksworth/html-time/blob/b9722a2e532e07ada5c9e2472f38e518e2385371/netlify/edge-functions/time.ts) and be done.

That's what you'll find if you visit [setyourwatchby.netlify.app](https://setyourwatchby.netlify.app) now. Your request will be intercepted by an Edge Function running on Netlify's CDN which will determine your locale based on your IP address, and insert your current time into the HTML that it is sending to you.

No more regular redeployments for this little demo site.

## But what did I learn?

Over the course of millions of unattended deployments, I did learn a few things.

### 1. Don't let your mistakes "leave the kitchen"

Borrowing this notion from the catering trade, it's fine for mistakes to happen in the kitchen, but they must never reach the diner. Automating deployment on this (or any) scale is possible thanks to the model where builds which fail do not result in a deployment being published. 

My logs show that I had a few handfuls of builds which failed over the course of the millions of deployments since 2018, but they never worried me. The previous good deploy would always be visible until replaced by a new one, so at worst the time would be a wrong for one minute if a build broke or was skipped.

This level of confidence in automation is key to its success. And these days we include all sorts of tests to our automated builds to check for accessibility, performance, and other integrity before they can "leave the kitchen" and take their final journey out to the hosting infrastructure.

### 2. Knowledge is power

A model of [immutable deployments](https://jamstack.org/glossary/immutable/), where each new build becomes an instance of the site which can live on in perpetuity, is incredibly powerful and liberating. By retaining every "known state" of a site over the course of its life, you gain the ability to redeploy any previous version of the site in milliseconds. Or to address any version of the site via a unique URL. Risk plummets when you know that you're not disrupting the integrity of your site, and can always revert.

For posterity, [here is what the site looked like](https://6177423cb626b90007b2a5d1--setyourwatchby.netlify.app/) the very last time it was automatically redeployed.


### 3. Automating got easier

In 2018, I used a third party service to trigger a build of the site every minute. You can create webhooks on Netlify which trigger a build when called so this worked nicely.

Since then, Netlify released [Scheduled Functions](https://www.netlify.com/products/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch/#scheduled-functions) which give a cron-like interface for executing a serverless function. If I were to need to redeploy a site regularly these days, I'd use these to reduce the number of external services in play and make my life a little simpler.


## Try Edge Functions yourself

If you want to learn more about Netlify Edge Functions you can [explore some examples here](https://edge-functions-examples.netlify.app/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch), or [visit the docs](https://docs.netlify.com/edge-functions/overview/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch). Scheduled Functions are also very handy and simple to use, and you can find [their docs here](https://docs.netlify.com/netlify-labs/experimental-features/scheduled-functions/?utm_campaign=devex_pnh&utm_source=devto&utm_medium=web&utm_content=night-night-setyourwatch).

Lastly, if you want to know the time, you can still visit [setyourwatchby.netlify.app](https://setyourwatchby.netlify.app), but I suspect you might have some other resources to help you with that :)