<commit_before>---
owner_slack: "#govuk-developers"
title: Architectural deep-dive of GOV.UK
section: Applications
type: learn
layout: manual_layout
parent: "/manual.html"
last_reviewed_on: 2020-04-08
review_in: 12 months
---

We can cover a lot of GOV.UK architecture by asking ourselves three questions:

1. What happens when a user visits a page on GOV.UK?
2. What happens when a publisher hits 'Publish'?
3. What happens when a developer deploys a change to an application?

[GOV.UK]: https://www.gov.uk

## What happens when a user visits a page on GOV.UK?

### DNS

![](images/dns.png)

The browser queries a local DNS server to turn the domain name into an IP address.
The local DNS server might be able to answer immediately from its cache. If not,
it will query the authoritative name servers for the domain.

`gov.uk.` is a country-code second-level domain or ccSLD (like `co.uk.`) and its
authoritative servers are hosted by [Jisc]. Unusually for a ccSLD, `gov.uk` is
also a website, and hosts the redirect from `gov.uk` to `www.gov.uk`. The records
for these two domains are within the `gov.uk` second-level zone hosted by Jisc.

GDS hosts several third-level domains under `gov.uk` on [Amazon Route53], for
example `service.gov.uk`. The configuration for these is in the
[govuk-dns-config repo] and is deployed using code from the [govuk-dns repo].

`www.gov.uk` is a CNAME record which ultimately points to `www-gov-uk.map.fastly.net.`
The `fastly.net` domain name is hosted by special nameservers at the Fastly content
delivery network, which aim to respond with the IP address of the Fastly cache node
which is "closest" to the user. Read more about Fastly in the next section, or
[read more about gov.uk DNS][govuk-dns-docs].

[govuk-dns repo]: https://github.com/alphagov/govuk-dns
[govuk-dns-config repo]: https://github.com/alphagov/govuk-dns-config
[govuk-dns-docs]: /manual/dns.html
[Jisc]: https://www.jisc.ac.uk/domain-registry
[Amazon Route53]: https://aws.amazon.com/route53/

### CDN and caching

GOV.UK uses the [Fastly] CDN to handle the majority of requests, which - as
well as reducing load on GOV.UK ('origin') by around 70% - provides 'edge nodes'
(servers) that are closer to our end users (particularly those outside the UK).

Fastly uses [Varnish] for caching, with a default cache time of 1 hour. (Read
["Our content delivery network"][our-cdn] for more information). If Fastly
doesn't have a page in its cache, it fetches the page from origin.

[Caches can be purged][purge-cache] using the [cache-clearing-service], which
tells Fastly to soft-purge (i.e. only remove the cached version once it has
received the new version from origin). This cache clearing service is
triggered automatically when pages are updated - more on that later.

[cache-clearing-service]: https://github.com/alphagov/cache-clearing-service
[Fastly]: https://www.fastly.com/
[our-cdn]: /manual/cdn.html
[purge-cache]: /manual/purge-cache.html
[Varnish]: https://varnish-cache.org/<commit_msg>Explain deploying DNS, and multiple DNS providers<commit_after>---
owner_slack: "#govuk-developers"
title: Architectural deep-dive of GOV.UK
section: Applications
type: learn
layout: manual_layout
parent: "/manual.html"
last_reviewed_on: 2020-04-08
review_in: 12 months
---

We can cover a lot of GOV.UK architecture by asking ourselves three questions:

1. What happens when a user visits a page on GOV.UK?
2. What happens when a publisher hits 'Publish'?
3. What happens when a developer deploys a change to an application?

[GOV.UK]: https://www.gov.uk

## What happens when a user visits a page on GOV.UK?

### DNS

![](images/dns.png)

The browser queries a local DNS server to turn the domain name into an IP address.
The local DNS server might be able to answer immediately from its cache. If not,
it will query the authoritative name servers for the domain.

`gov.uk.` is a country-code second-level domain or ccSLD (like `co.uk.`) and its
authoritative servers are hosted by [Jisc]. Unusually for a ccSLD, `gov.uk` is
also a website, and hosts the redirect from `gov.uk` to `www.gov.uk`. The records
for these two domains are within the `gov.uk` second-level zone hosted by Jisc.

GDS hosts the DNS for third-level domains under `gov.uk` (for example `service.gov.uk`)
on both [Amazon Route53] and Google Cloud Platform, for redundancy. The configuration
for these domains is in the [govuk-dns-config repo], which is deployed via the
[Deploy_DNS Jenkins job][deploy-dns], which in turn references the [govuk-dns repo].

`www.gov.uk` is a CNAME record which ultimately points to `www-gov-uk.map.fastly.net.`
The `fastly.net` domain name is hosted by special nameservers at the Fastly content
delivery network, which aim to respond with the IP address of the Fastly cache node
which is "closest" to the user. Read more about Fastly in the next section, or
[read more about gov.uk DNS][govuk-dns-docs].

[deploy-dns]: https://deploy.publishing.service.gov.uk/job/Deploy_DNS/
[govuk-dns repo]: https://github.com/alphagov/govuk-dns
[govuk-dns-config repo]: https://github.com/alphagov/govuk-dns-config
[govuk-dns-docs]: /manual/dns.html
[Jisc]: https://www.jisc.ac.uk/domain-registry
[Amazon Route53]: https://aws.amazon.com/route53/

### CDN and caching

GOV.UK uses the [Fastly] CDN to handle the majority of requests, which - as
well as reducing load on GOV.UK ('origin') by around 70% - provides 'edge nodes'
(servers) that are closer to our end users (particularly those outside the UK).

Fastly uses [Varnish] for caching, with a default cache time of 1 hour. (Read
["Our content delivery network"][our-cdn] for more information). If Fastly
doesn't have a page in its cache, it fetches the page from origin.

[Caches can be purged][purge-cache] using the [cache-clearing-service], which
tells Fastly to soft-purge (i.e. only remove the cached version once it has
received the new version from origin). This cache clearing service is
triggered automatically when pages are updated - more on that later.

[cache-clearing-service]: https://github.com/alphagov/cache-clearing-service
[Fastly]: https://www.fastly.com/
[our-cdn]: /manual/cdn.html
[purge-cache]: /manual/purge-cache.html
[Varnish]: https://varnish-cache.org/
{'fraction_non_alphanumeric': 0.10136327185244587, 'fraction_numerical': 0.007056936647955092, 'mean_word_length': 4.293718166383702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 17, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1779445', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1911, 'n_words': 827}