<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://blog.readthedocs.com</id>
  <title>Read the Docs Blog - Posts tagged community</title>
  <updated>2023-07-08T10:50:30.099326+00:00</updated>
  <link href="https://blog.readthedocs.com"/>
  <link href="https://blog.readthedocs.com/archive/tag/community/atom.xml" rel="self"/>
  <generator uri="https://ablog.readthedocs.org/" version="0.10.26">ABlog</generator>
  <entry>
    <id>https://blog.readthedocs.com/announcing-community-cdn/</id>
    <title>Shipping a CDN on Read the Docs Community</title>
    <updated>2020-05-18T00:00:00+00:00</updated>
    <author>
      <name>Eric Holscher</name>
    </author>
    <content type="html">&lt;section id="shipping-a-cdn-on-read-the-docs-community"&gt;

&lt;p&gt;You might have noticed that our Read the Docs Community site has gotten faster in the past few weeks.
How much faster likely depends on how far away you live from Virginia,
which is where our servers have traditionally lived.&lt;/p&gt;
&lt;p&gt;We have recently enabled a CDN on &lt;strong&gt;all Read the Docs Community sites&lt;/strong&gt;,
generously sponsored by &lt;a class="reference external" href="https://www.cloudflare.com/"&gt;CloudFlare&lt;/a&gt;.
This post will talk a bit more about how we implemented this,
and why we’re excited about it.&lt;/p&gt;
&lt;p&gt;We are also offering the CDN option to our Read the Docs for Business users on the Enterprise plan,
you can &lt;a class="reference external" href="mailto:support&amp;#37;&amp;#52;&amp;#48;readthedocs&amp;#46;org"&gt;reach out&lt;/a&gt; to us if you’re interested.&lt;/p&gt;
&lt;section id="hosting-thousands-of-domains-is-hard"&gt;
&lt;h2&gt;Hosting thousands of domains is hard&lt;/h2&gt;
&lt;p&gt;Traditionally the largest problem that we’ve had with rolling out features to all of our documentation sites is scale.
We host thousands of custom domains for our users,
and any solution needs to work across all of them.
This has presented a number of issues in the past,
but CDN is one of the most complicated.&lt;/p&gt;
&lt;p&gt;To make a CDN function across all our sites,
every data center that the CDN has needs to work with all our custom domains.
Imagine we have 5,000 domains and there are 100 data centers across the world,
this means that &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;5,000&lt;/span&gt; &lt;span class="pre"&gt;*&lt;/span&gt; &lt;span class="pre"&gt;100&lt;/span&gt; &lt;span class="pre"&gt;=&lt;/span&gt; &lt;span class="pre"&gt;500,000&lt;/span&gt;&lt;/code&gt; different endpoints need to be configured for this to work at scale.&lt;/p&gt;
&lt;p&gt;We are lucky that CloudFlare has the global scale to be able to donate us this service.
Specifically,
their &lt;a class="reference external" href="https://www.cloudflare.com/ssl-for-saas-providers/"&gt;SSL for SAAS&lt;/a&gt; service is what we’re using for both SSL and CDN across all our custom domains.
This allows us to offload the complexity to CloudFlare,
and only focus on our integration.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="implementation"&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;One of the coolest things that CloudFlare’s CDN offers is something called &lt;a class="reference external" href="https://support.cloudflare.com/hc/en-us/articles/200169246-Purging-cached-resources-from-Cloudflare#h_6d756ac9-c476-45e8-a5d4-e2a6e45d9dc7"&gt;Cache Tags&lt;/a&gt;.
This lets us add a &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;Cache-Tag&lt;/span&gt;&lt;/code&gt; header to all the documentation that we serve,
and invalidate the cache using just that tag.&lt;/p&gt;
&lt;p&gt;An example,
when you load our docs,
we will return a header:&lt;/p&gt;
&lt;div class="highlight-default notranslate"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;GET&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readthedocs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;en&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;latest&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We return a tag that matches both the &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;$project&lt;/span&gt;&lt;/code&gt;, and the &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;$project-$version&lt;/span&gt;&lt;/code&gt;.
This allows us to invalidate the cache for a specific version,
or across the entire project.&lt;/p&gt;
&lt;p&gt;As you know,
cache invalidation is one of the harder problems,
so we take a pretty conservative approach.
We invalidate the cache in the following scenarios:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Project cache on Project or Domain save&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Version cache on documentation builds for specific versions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The client code is quite simple,
a single HTTP request to Cloudflare’s API with a list of &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;tags&lt;/span&gt;&lt;/code&gt; to clear.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="outcomes"&gt;
&lt;h2&gt;Outcomes&lt;/h2&gt;
&lt;p&gt;There are two important outcomes from this work:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Page loads are much faster for users around the world&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our server load has gone down quite a lot because we handle fewer requests&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The biggest winner here is our users.
Docs are faster for everyone,
and we are looking at implementing additional features into our documentation hosting code now that we have reduced load.&lt;/p&gt;
&lt;p&gt;We hope that Read the Docs Community has gotten noticeably faster,
and that in the near future it will continue to get better with the new features that this enables.&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
</content>
    <link href="https://blog.readthedocs.com/announcing-community-cdn/" rel="alternate"/>
    <summary>You might have noticed that our Read the Docs Community site has gotten faster in the past few weeks.
How much faster likely depends on how far away you live from Virginia,
which is where our servers have traditionally lived.We have recently enabled a CDN on all Read the Docs Community sites,
generously sponsored by CloudFlare.
This post will talk a bit more about how we implemented this,
and why we’re excited about it.</summary>
    <category term="community" label="community"/>
    <category term="cdn" label="cdn"/>
    <category term="hosting" label="hosting"/>
    <published>2020-05-18T00:00:00+00:00</published>
  </entry>
</feed>
