<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Erik Witt on Medium]]></title>
        <description><![CDATA[Stories by Erik Witt on Medium]]></description>
        <link>https://medium.com/@erik.witt?source=rss-d4e2bf391735------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6bSSBLWO72uA-3cQdpOf1w.jpeg</url>
            <title>Stories by Erik Witt on Medium</title>
            <link>https://medium.com/@erik.witt?source=rss-d4e2bf391735------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 16:11:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erik.witt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Video: Service Workers in Action — Building an Offline-Capable Webshop in under 90 minutes]]></title>
            <link>https://medium.com/baqend-blog/video-service-workers-in-action-building-an-offline-capable-webshop-in-under-90-minutes-2c3f203ffe30?source=rss-d4e2bf391735------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c3f203ffe30</guid>
            <category><![CDATA[progressive-web-app]]></category>
            <category><![CDATA[e-commerce-business]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[service-worker]]></category>
            <dc:creator><![CDATA[Erik Witt]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 12:53:19 GMT</pubDate>
            <atom:updated>2019-12-14T12:53:19.978Z</atom:updated>
            <content:encoded><![CDATA[<h3>Video: Service Workers in Action — Building an Offline-Capable Webshop in under 90 minutes</h3><p><em>Recently on at code.talks 2019 in Hamburg, we held a hackathon to showcase how the Service Worker Web standard can be used to fight long loading times in modern e-commerce. You can find a video of our talk and the abstract below. We hope you enjoy!</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6SnqETJ8MVU%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6SnqETJ8MVU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6SnqETJ8MVU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9fcdaf59ff83aa9a316103162469ec7/href">https://medium.com/media/c9fcdaf59ff83aa9a316103162469ec7/href</a></iframe><p>2019 is the year of Progressive Web Apps: With Service Worker support in every major browser, tight integration into Google’s and Microsoft’s app stores, and even Desktop PWAs in Chrome on every platform, PWAs have started to take over mobile and even desktop app development. Just the right time to see what all the fuzz is about.</p><p>In this hackathon, we will provide a deep-dive into the Service Worker standard by turning the most basic website you can imagine into an offline-capable PWA showcasing the most awesome Service Worker capabilities. We will add new features step-by-step to illustrate add-to-homescreen functionality, the offline mode, push notifications, and the different caching strategies, each with their own example. As we go, we will provide background information on scopes, lifecycles, persistence, and other pivotal concepts and we will talk about the many quirks and pitfalls we have encountered in the last two years. Finally, we will provide an overview over the exciting features and APIs that are yet to come (e.g. for payment, credentials, sharing, and speech processing). No special hardware needed!</p><p>Check out <a href="https://speedstudy.info/"><strong>speedstudy.info</strong></a><strong> </strong>to learn why websites are often slow, how you can make them faster, and why this will boost your business success!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*geQH1QkgACQaUuIwZ8yd0Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c3f203ffe30" width="1" height="1" alt=""><hr><p><a href="https://medium.com/baqend-blog/video-service-workers-in-action-building-an-offline-capable-webshop-in-under-90-minutes-2c3f203ffe30">Video: Service Workers in Action — Building an Offline-Capable Webshop in under 90 minutes</a> was originally published in <a href="https://medium.com/baqend-blog">Speed Kit Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chrome's Service Workers Break HTTP/2 Priorities]]></title>
            <link>https://medium.com/baqend-blog/chromes-service-workers-break-http-2-priorities-649c4e0fa930?source=rss-d4e2bf391735------2</link>
            <guid isPermaLink="false">https://medium.com/p/649c4e0fa930</guid>
            <category><![CDATA[firefox]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Erik Witt]]></dc:creator>
            <pubDate>Thu, 09 Aug 2018 16:09:32 GMT</pubDate>
            <atom:updated>2018-08-10T09:11:52.397Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chrome’s Service Workers Break HTTP/2 Priorities</h3><p>Today, we encountered a huge problem with Chrome’s Service Worker implementation in combination with HTTP/2.</p><p>As long as Developers cannot <strong>specify priorities</strong> in the <em>fetch()</em><strong> API</strong> there is a huge performance problem with Service Workers.</p><h3>The Issue</h3><blockquote>Requests lose all HTTP/2 stream dependencies when requested through a Service Worker with extreme effects on page load time.</blockquote><h3>Discussion in Twitter</h3><p>The issue triggered a lot of interesting discussion on twitter.</p><h3>Jake Archibald on Twitter</h3><p>@yoavweiss @addyosmani @slightlylate @EWErikWitt @igrigorik @domfarolino Oh, I stand corrected. Yes, this should absolutely be copied. I&#39;ll get a PR together.</p><h3>Yoav Weiss on Twitter</h3><p>@slightlylate @EWErikWitt @igrigorik @jaffathecake I somehow thought the priority info is copied over to the new request, even if it&#39;s not publicly available. If it isn&#39;t, it increases the urgency of the fetch() part of Priority Hints (although the fetch() would still have unwanted side effects) /cc @domfarolino @addyosmani</p><h3>Addy Osmani on Twitter</h3><p>@yoavweiss @slightlylate @EWErikWitt @igrigorik @jaffathecake @domfarolino Was any behaviour around maintaining same priority for the new Request spec&#39;d? If not, I&#39;d concur this does suggest we need Priority Hints for fetch() sooner rather than later.</p><h3>Explaining the Issue</h3><p>To illustrate that, we built a stripped-down <a href="https://testpage-speedkit.app.baqend.com/">website</a>, which loads a <a href="https://testpage-speedkit.app.baqend.com/styles.css">CSS file</a>and 80 small red images. The CSS imports <a href="https://testpage-speedkit.app.baqend.com/font.css">another CSS</a> with fonts in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*EFm2cXhMCKzqnjxbb1DX1g.png" /><figcaption><a href="https://testpage-speedkit.app.baqend.com/">https://testpage-speedkit.app.baqend.com/</a></figcaption></figure><p><strong>Without a Service Worker</strong>, the site loads as follows:</p><ol><li>the HTML is loaded.</li><li>the <em>style.css</em> and all the image request are fired in parallel, with the CSS having the highest priority.</li><li>When the <em>style.css</em> has finished loading, the <em>font.css</em> request is fired with a very high priority.</li><li>After the <em>font.css</em> finishes loading, the <strong>page is painted</strong> for the first time (even though some of the images have not finished loading, yet).</li></ol><p>The <strong>waterfall</strong> without the Service Worker, however, looks as expected. Obviously, importing one CSS in another is an anti-pattern, but it is very good for illustrating the issue we are about to encounter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*DSoxksPrpTwK7Qsm7cgelA.png" /><figcaption><a href="https://www.webpagetest.org/result/180809_J9_ce853b30bac6f9b1d0674213e9681b2c/1/details/#waterfall_view_step2">The WebPagetest waterfall without Service Worker</a></figcaption></figure><p>The <strong>actual problem</strong> starts, when we add a very <a href="https://testpage-speedkit.app.baqend.com/simple.js">simple Service Worker</a> to the page which only forwards requests to the network:</p><pre>addEventListener(&#39;fetch&#39;, event =&gt; {<br>  event.respondWith(fetch(event.request));<br>});</pre><p>With the Service Worker installed, the page loads similarly to before: After the HTML, the <em>style.css</em> is requested in parallel with all the images with the CSS having the highest priority. When the <em>style.css</em> finishes loading, the <em>fonts.css</em> is requested. The problem: the <em>style.css</em> is loaded with the lowest priority of the all the requests, even though it blocks rendering and is only 0.6 KB in size.</p><ol><li>The HTML is loaded.</li><li>the <em>style.css</em> and all the image request are fired in parallel, with the CSS having the highest priority.</li><li>When the <em>style.css</em> has finished loading, the <em>font.css</em> request is fired.</li><li><strong>The problem:</strong> the <em>font.css</em> is loaded with the lowest priority of all the requests, even though it blocks rendering and is only 0.6 KB in size.</li></ol><p>The effect is that the <strong>render blocking CSS is loaded last</strong> and therefore <strong>delays the paint from 3 seconds to over 6 seconds:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*mstUKJbNqweUZldt-eVxZA.png" /><figcaption><a href="https://www.webpagetest.org/result/180809_0W_19b7ffebc47212324553fa6e5c5a5b57/1/details/#waterfall_view_step2">The WebPagetest waterfall with Service Worker</a></figcaption></figure><p>The request details in the waterfalls clearly show that the HTTP/2 stream dependencies and <strong>priorities are lost</strong> when the requests are proxied through the Service Worker.</p><p><strong>Without the Service Worker</strong>, the CSS HTTP/2 stream depends on stream 0, which is the HTML request. This means the CSS is loaded in parallel with all the images.</p><p><strong>With the Service Worker</strong>, the CSS stream depends on stream 169, which is the last image. This means the CSS is loaded as the very last resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*bg0yKJqpySC6WQQtkswMIw.png" /><figcaption>HTTP/2 stream dependency and weight <strong>without</strong> Service Worker</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*Run8FTfeIn7azZEuC4SqBg.png" /><figcaption>HTTP/2 stream dependency and weight <strong>with</strong> Service Worker</figcaption></figure><p>In summary, Chrome <strong>prioritizes</strong> all requests that are proxied through the Service Worker, in the order, they are fetched in the Service Worker. I.e. request 5 depends on request 4 depends on request 3 and so on.</p><h3>Firefox</h3><p>Firefox appears to have a similarly problematic approach. Every request that is proxied through the Service Worker gets the same priority that looks like this:</p><p><strong>HTTP/2 Stream: </strong>X, weight 22, depends on 11</p><p>Sadly since the release of the new WebPagetest agent, we cannot see the HTTP/2 priorities in the waterfalls, but still, here they are <a href="https://www.webpagetest.org/result/180809_0M_c5a0204b083e77d6fc92ef756635ecee/1/details/#waterfall_view_step2">without Service Worker</a> and <a href="https://www.webpagetest.org/result/180809_VJ_9097a5a3ac07fd16ea65c626d4ad0a1d/1/details/#waterfall_view_step2">with Service Worker</a>.</p><h3>Conclusion</h3><p>We are big fans of HTTP/2 and multiplexing, but correct resource dependencies and weights are essential. The issue appears to be described briefly in <a href="https://www.researchgate.net/publication/324514529_HTTP2_Prioritization_and_its_Impact_on_Web_Performance">this paper in section 4.4</a>.</p><p>In case we missed something or there is another way to avoid losing request priorities, please give us a hint, it would be highly appreciated. We have filed a bug report for this issue at <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=872776">https://bugs.chromium.org/p/chromium/issues/detail?id=872776</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=649c4e0fa930" width="1" height="1" alt=""><hr><p><a href="https://medium.com/baqend-blog/chromes-service-workers-break-http-2-priorities-649c4e0fa930">Chrome&#39;s Service Workers Break HTTP/2 Priorities</a> was originally published in <a href="https://medium.com/baqend-blog">Speed Kit Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Performance in a Nutshell: HTTP/2, CDNs and Browser Caching]]></title>
            <link>https://medium.com/baqend-blog/hosting-lessons-learned-6010992eb257?source=rss-d4e2bf391735------2</link>
            <guid isPermaLink="false">https://medium.com/p/6010992eb257</guid>
            <category><![CDATA[web-hosting]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[web-performance]]></category>
            <dc:creator><![CDATA[Erik Witt]]></dc:creator>
            <pubDate>Fri, 24 Mar 2017 15:31:26 GMT</pubDate>
            <atom:updated>2017-05-04T16:44:41.882Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Successful websites need to be fast, scalable and secure. In this article we survey the state of the art of high-performance websites, in particular SSL encryption, HTTP/2, CDNs and browser caching. We’ll cover the major performance optimizations and show how we did it in <a href="https://medium.com/@erik.witt/hosting-on-baqend-1ead24a7784a">our setup</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFxpqowyGx3qomeojYVyLg.png" /></figure><p>Building a <strong>static website</strong> today is easier than ever. There are so <a href="https://wrapbootstrap.com/">many</a> <a href="https://startbootstrap.com/">great</a> <a href="https://startbootstrap.com/bootstrap-resources/">things</a> you can use to build a stunning landing page, blog or whatever you want. With static site generators like <a href="https://jekyllrb.com/">Jekyll</a>, <a href="https://gohugo.io/">Hugo</a>, <a href="http://octopress.org/">Octopress</a> or <a href="https://hexo.io/">Hexo</a> you can even take this to the next level and build your site hassling much less with <strong>HTML</strong>, <strong>CSS</strong> or <strong>JavaScript</strong>. Github pages, for example, are rendered with Jekyll.</p><p>So almost anyone can build a great website today. There is one last step before becoming <strong>rich and famous</strong>, though: You need to <strong>host</strong> the site somewhere on the internet to make it accessible to everyone. That’s going to be <strong>just as easy</strong>, right? Well, not exactly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HH2lLsrrrFdTxrESgWYLYw.png" /><figcaption>Example of a static <a href="https://www.everymillisecondcounts.eu/old/">website</a> hosted in central Europe and loaded from the US.</figcaption></figure><p>Putting the site on a <strong>server</strong> and setting up a <strong>domain</strong> for it is simply not enough these days. For a great website to be successful, it needs to excel in three things: <strong>speed</strong>, <strong>scalability</strong> and <strong>security</strong>.</p><h3>State-of-the-Art Hosting</h3><p>Especially with static sites, these requirements are not all that hard to achieve — in theory. But let’s take a look at what needs to be done <em>in practice</em>.</p><h4>HTTPS (SSL/TLS Encryption)</h4><blockquote>I know what you are thinking: Do I really need SSL for my website? The simple answer is: You do!</blockquote><p>HTTPS does not only protect <strong>sensitive information</strong> like passwords, payment data or simply the user’s <strong>identity</strong>, but also provides <strong>authentication</strong> to make users confident they are surfing the legit website. HTTPS further ensures <strong>integrity,</strong> meaning no one can alter your content by, say, <a href="https://www.theguardian.com/technology/2015/may/07/ad-injection-software-browser-extensions-google-malware">injecting ads without your permission</a>. SSL simply <strong>builds trust. </strong>Browsers acknowledge that by <strong>highlighting secure websites</strong> or, in case of Google Chrome, labeling <a href="https://www.chromium.org/Home/chromium-security/marking-http-as-non-secure">non-HTTPS websites as <strong><em>Not Secure</em></strong></a>. Also, with all current browsers, HTTPS is mandatory for <strong>HTTP/2</strong>– and you really want that for speed, but more on that later. Furthmore, Google <a href="http://searchengineland.com/google-starts-giving-ranking-boost-secure-httpsssl-sites-199446">boosts your <strong>SEO rank</strong></a>, if your site uses HTTPS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5UzrdI6ME2sb8cCJ_rL_6A.png" /><figcaption>Browsers highlight secure websites which builds trust.</figcaption></figure><p>Regarding the <strong>setup</strong>, things have become much easier with the <a href="https://letsencrypt.org/">Let’s Encrypt</a> project. They <strong>generate certificates</strong> for free and there is <a href="https://www.nginx.com/blog/free-certificates-lets-encrypt-and-nginx/">tooling</a> to fully automate domain authorization and certificate signing. But even with Let’s Encrypt, you still need to figure out how to <strong>install certificates</strong> on your server (or CDN), make sure <strong>the certificates are renewed </strong>on time (expiring every 3 month) and probably <strong>enforce their usage</strong> by configuring <a href="https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security">HSTS headers</a> to prevent protocol downgrade attacks.</p><p>But HTTPS is not only notoriously hard to set up from scratch, it also effects website performance if you don’t take precautions:</p><ol><li>Encryption is always hard on the <strong>CPU</strong> and <strong>TLS encryption</strong> will certainly add some <strong>overhead</strong> to your server-side processing. Keep that in mind for server capacity planning. An autoscaling server infrastructure that monitors <strong>throughput</strong>, deals with <strong>load spikes </strong>and ensures <strong>availability</strong> will be discussed below<strong>.</strong></li><li>The initial <strong>TLS handshake</strong> adds 2 additional roundtrips to the TCP handshake, which itself already needs 2, resulting in a <strong>4 roundtrip handshake</strong>. Depending on the distance between client and server this can amount to <strong>more than a second</strong> only to set up the first connection. To speed up the handshake, you need to make sure that your server supports <a href="https://en.wikipedia.org/wiki/TCP_Fast_Open"><strong>TCP Fast Open</strong></a> as well as <a href="https://blogs.windows.com/msedgedev/2016/06/15/building-a-faster-and-more-secure-web-with-tcp-fast-open-tls-false-start-and-tls-1-3/#BqAGYfpLwoYCtE6i.97"><strong>TLS False Start</strong></a> and <a href="https://timtaubert.de/blog/2014/11/the-sad-state-of-server-side-tls-session-resumption-implementations/"><strong>Session Resumption</strong></a>. These will halve the time of your handshake. There are even more considerations (e.g. dynamic packet sizing), of which Ilya Grigorik from the Google web performance team gives a <a href="https://istlsfastyet.com/">great round-up</a>.</li><li>The most important optimization, though, is to use <strong>HTTP/2</strong> with all its benefits. Getting rid of domain sharding and using a single HTTP/2 connection instead can already save you expensive connection setups.</li></ol><p>In essence, HTTPS is required for <strong>customer trust</strong> and <strong>security</strong>, but even with state-of-the-art tooling it <strong>impedes fast loading times</strong> and thus can diminish <strong>customer satisfaction</strong>. Also, the <strong>complexity</strong> of setting things up smoothly keeps many website providers from using HTTPS in the first place.</p><h4>HTTP/2</h4><p>If you have HTTPS, you definitely want HTTP/2 (also called <strong>h2</strong>). The second major protocol version of HTTP has lots of optimizations and features that fix <a href="http://queue.acm.org/detail.cfm?id=2555617"><strong>common HTTP/1.1 problems</strong></a>. It comes with <strong>server push</strong> to transfer multiple resources for a single request, <strong>header compression </strong>to drive down request and response sizes and also request <strong>pipelining</strong> and <strong>multiplexing</strong> to send arbitrary parallel requests over a single TCP connection. With server push, you can for example push the CSS and JS right after shipping your HTML without waiting for the actual request.</p><p>Multiplexing and pipelining make a <strong>huge difference</strong>, in particular for websites with many assets such as images or videos. Take a look at this <a href="http://http2.golang.org/gophertiles?latency=1000">live comparison</a> as well as the following example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q1Ao7prx0BM1l3sTI8z3CA.png" /><figcaption>An example showing the impact of pipelining and multiplexing in HTTP/2.</figcaption></figure><p>You can see how HTTP/1.1 is limited to 6 concurrent connections, each of which can only load a single resource at a time. With HTTP/2 in contrast, all resources are fetched in parallel.</p><p>But even HTTP/2 cannot trick physics and thus page load times are ultimately <strong>driven by the latency</strong> of each individual request. The only way to decrease that latency is to<strong> bring data closer to your clients</strong>. This brings us to the topic of caching.</p><h4>Content Delivery Networks (CDNs)</h4><p>In a nutshell, CDNs are <strong>globally distributed cache infrastructures</strong> that store <a href="https://gtmetrix.com/why-use-a-cdn.html"><strong>mostly static</strong></a><strong> </strong>data in various locations. If a user accesses a CDN-backed website, she connects to the <strong>nearest edge location </strong>via Geo-DNS or <a href="https://en.wikipedia.org/wiki/Anycast">IP Anycast</a> and gets all cached resources from there. Using this nearby copy of the data <strong>highly decreases</strong> request latency and therefore page load time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FDownrightGloriousIguanodon&amp;url=https%3A%2F%2Fgfycat.com%2FDownrightGloriousIguanodon&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FDownrightGloriousIguanodon-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="2160" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a44df7d433b2f022b678c5307eace7b/href">https://medium.com/media/4a44df7d433b2f022b678c5307eace7b/href</a></iframe><p>The CDN has to fetch all uncached (or even uncachable) resources from the application server. One advantage of proxying all requests through the CDN is a faster connection setup for clients. Because the CDN <strong>terminates HTTPS connections</strong>, a client only performs a fast TLS handshake with the nearby CDN edge server. The connection from the CDN to the server again is HTTPS and should be configured as a <a href="https://en.wikipedia.org/wiki/HTTP_persistent_connection"><strong>persistent connection</strong></a> to save expensive handshakes.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FFrenchSpanishChafer&amp;url=https%3A%2F%2Fgfycat.com%2FFrenchSpanishChafer&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FFrenchSpanishChafer-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="2160" height="556" frameborder="0" scrolling="no"><a href="https://medium.com/media/e64708ae1eced3f04f0a451b71c3a697/href">https://medium.com/media/e64708ae1eced3f04f0a451b71c3a697/href</a></iframe><p>Even though CDN edge servers are generally nearby, even a few tens of milliseconds per request can add up to a considerable delay. So let’s take a look at caching on the next level of the web stack.</p><h4>Browser Caching</h4><blockquote>The fastest request is the one you don’t make.</blockquote><p>Browser caching is extremely efficient, especially for <strong>repeated page views</strong> and navigating through a website. Every request for a cached resource returns <strong>instantly</strong> and thus does not use a connection nor any bandwidth.</p><p>The browser cache is an <strong>expiration-based</strong> cache that operates based on <a href="https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Cache-Control"><strong>cache-control headers</strong></a>. Every cacheable object needs a time-to-live (TTL) set by the server via the <strong>max-age header</strong>. This value represents the time the cached entry is considered up-to-date. When the resource is requested after the TTL has expired, it has to be retrieved from the original server to make sure it is up-to-date. For versioned resources with <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag"><strong>ETag header</strong></a><strong> or Last-Modified</strong>, bandwidth is saved by transmitting a <strong>Status 304 message</strong> (Not Modified) instead of the actual resource whenever the version hasn’t changed.</p><p>The browser cache is great for storing assets like CSS, JavaScript, fonts, icons and even images, because they are slow to retrieve over the network and usually do not change often, if at all. <strong>Problems</strong> arise, however, when those assets change before their TTL expires, because then the cache returns stale resource versions. In order to cache these <strong>mutable assets,</strong> too, we have to use <a href="http://webassets.readthedocs.io/en/latest/expiring.html"><strong>asset hashing</strong></a>. That means, a hash of the asset’s content is appended to its name and all <strong>references</strong> to it. If the asset changes, its name and references change as well and the resource can be cached safely. The good news is that build tools <a href="https://medium.com/@okonetchnikov/long-term-caching-of-static-assets-with-webpack-1ecb139adb95#.z8r2hi4ts">like webpack</a> can already do asset hashing for you.</p><p>In summary, it is essential to use the browser cache correctly and for as <strong>many resources</strong> as possible. Configuring cache-control headers on the server side as well as setting up asset hashing can be quite complex, but it is an absolute must for competitive website performance.</p><h4>Load-Balancing</h4><p>The obvious <strong>worst case</strong> for a website is an <strong>overload</strong> situation during which the server has to <strong>drop user requests</strong> or even completely <strong>breaks down</strong>.</p><p>In order to cope with a high number of visitors or <strong>load spikes, </strong>we need our server infrastructure to <strong>scale horizontally.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FScalyFrayedHogget&amp;url=https%3A%2F%2Fgfycat.com%2FScalyFrayedHogget&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FScalyFrayedHogget-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="2116" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cb8b1be07860a0c12c47333f099ed85/href">https://medium.com/media/9cb8b1be07860a0c12c47333f099ed85/href</a></iframe><p>The setup above shows a <strong>load balancer</strong> that <strong>uniformly distributes</strong> request over a number of stateless application servers. <strong>Statelessness is key</strong> here, because the load balancer does’t need to handle sticky sessions and the servers do not have to <strong>communicate</strong> with each other. Furthermore, it ensures <strong>fault tolerance</strong>, since <strong>failed servers</strong> are detected by the load balancer and removed from the routing protocol. Advanced load balancers can even use factors such as server capacity and response time to choose a server.</p><p>Stateless servers are also easy to <strong>scale dynamically</strong> depending on the load. To <strong>scale up</strong>, you simply start an additional server and register it at the load balancer. To <strong>scale down</strong>, the load balancer <strong>drains all active connections</strong> to the server before shutting it down. This dynamic scalability needs to be combined with server resource monitoring to implement <strong>autoscaling</strong>.</p><h4>Hosting Summary</h4><p>To wrap things up, a website can be made <strong>fast</strong>, <strong>scalable</strong> and <strong>secure</strong> by combining these technologies:</p><ul><li>HTTPS for security</li><li>HTTP/2 for performance and efficiency</li><li>CDN and browser caching for performance</li><li>Stateless servers, load balancing and autoscaling</li></ul><p>Admittedly, this is quite a lot to deal with, if all you want is to bring your content online. So why not have <strong>someone else</strong> take care of all the hassle?</p><h3>Our Setup</h3><p>With <a href="https://www.baqend.com/">Baqend</a>, we tried to make setting up state-of-the-art web hosting for a static site as easy as possible. We are a spin-off from database and web performance research and heavily focus on performance and scalability. There is a short blog post that will walk you through the process using an example website.</p><p><a href="https://medium.baqend.com/high-performance-website-hosting-with-ssl-and-http-2-made-simple-1ead24a7784a">High Performance Website Hosting with SSL and HTTP/2 Made Simple</a></p><h4>Clone Your Website</h4><p>If you want try out how your website could perform in this setup, execute the following commands in your console (with <a href="https://en.wikipedia.org/wiki/Wget"><strong>wget</strong> installed</a>). The example clones this blogpost to <strong>speed up Medium</strong> but you can replace the url with your <strong>own website</strong>:</p><pre>&gt; <strong>npm install -g baqend</strong><br>&gt; <strong>baqend register</strong><br><em>(your credentials...)</em><br>&gt; <strong>wget -E -H -k -p -nd -P www</strong> https://medium.baqend.com/hosting-lessons-learned-6010992eb257<br>&gt; <strong>mv</strong> www/hosting-lessons-learned-6010992eb257.html www/index.html<br>&gt; <strong>baqend deploy</strong><br>&gt; <strong>baqend open</strong></pre><p>The commands will (1) install the <strong>Baqend CLI</strong>, (2) register a new account with your given credentials, (3) clone your website into your current directory, (4) <strong>rename the html</strong> to index.html, (5) deploy the website to your <strong>free Baqend app</strong> and (6) open the website with the app’s default url.</p><p>If your website ins’t too complex, this will clone and deploy your main page. In our test we cloned <strong>this Medium post</strong> to <a href="https://clone-test.app.baqend.com/">https://clone-test.app.baqend.com/</a>. It makes quite a performance difference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZc6LbVeNodd5AFtf2TH7A.png" /><figcaption>Original load time vs load time of cloned website on Baqend (loaded from the US).</figcaption></figure><p>If your website is comparably simple you could actually use this as a very simple way to <strong>speed up your landingpage</strong>.</p><p>Obviously, you can optimize the cloned websites even more. The wget command isn’t perfect in this respect, after all. So let’s check out <strong>how fast</strong> websites in <strong>this setup</strong> actually get in the next section.</p><h3>Performance Measurements &amp; Comparison</h3><p>There are many great tools that let you analyze your website performance like <a href="https://webpagetest.org/">WebPageTest</a>, <a href="https://developers.google.com/speed/pagespeed/">Google PageSpeed</a> or <a href="https://gtmetrix.com/">GTmetrix</a>. We like to use GTmetrix because of its <strong>extensive report features</strong> and good <strong>rendering</strong> <strong>performance</strong>. Running it from <strong>Vancouver, Canada </strong>(with our backend standing in Frankfurt, Germany), we get an inital load time of <strong><em>300–400 ms</em></strong> for our example website <a href="https://www.everymillisecondcounts.eu/old/">everymillisecondcounts.eu</a> (see <a href="https://gtmetrix.com/reports/www.everymillisecondcounts.eu/pROixfJl">GTmetrix report</a>). A more comprehensive overview is given by this timing table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCqcU7RB8wCebd9aOSpReQ.png" /><figcaption>Timing for everymillisecondcounts.eu measured with GTmetrix from Vancouver.</figcaption></figure><p>For the second visit of the website, all resources except for the HTML come from the browser cache so that the page loads virtually in an instant.</p><p>To put Baqend’s hosting performance into perspective, we also tried a few other common configurations offered by other hosters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VB5_HP31S_XoOMtA6IM6g.png" /><figcaption>All load times measured from Canada with GTmetrix.</figcaption></figure><ul><li>With <strong>standard hosting</strong> on Amazon S3 in Frankfurt (Germany) the avg. load time from the US is <strong>3,22s</strong> with HTTP.</li><li>Adding SSL to the S3-hosted version, the initial load time climbs to<strong> 4,03s</strong>.</li><li>Hosted on Baqend (also located in Frankfurt), the avg. page load time is cut down to <strong>440 ms</strong> for HTTP.</li><li>With TLS encryption enabled, avg. page load time goes down even further to <strong>350 ms</strong> because of the use of HTTP/2.</li></ul><p>These performance improvements translate very well to more complex and even dynamic websites, because Baqend also caches dynamic data such as complex database queries — without any staleness for clients. For a live comparison with other providers, see our performance shoot-out:</p><p><a href="http://benchmark.baqend.com/">Live Performance Shoot-out</a></p><p>The hosting setup discussed in this post optimizes network as well as backend performance. If you feel your frontend performance needs improvements, take a look at another our blogpost on the most important web-performance techniques:</p><p><a href="https://medium.baqend.com/building-a-shop-with-sub-second-page-loads-lessons-learned-4bb1be3ed07">Building a Shop with Sub-Second Page Loads: Lessons Learned</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6010992eb257" width="1" height="1" alt=""><hr><p><a href="https://medium.com/baqend-blog/hosting-lessons-learned-6010992eb257">Web Performance in a Nutshell: HTTP/2, CDNs and Browser Caching</a> was originally published in <a href="https://medium.com/baqend-blog">Speed Kit Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[High Performance Website Hosting with SSL and HTTP/2 Made Simple]]></title>
            <link>https://medium.com/baqend-blog/high-performance-website-hosting-with-ssl-and-http-2-made-simple-1ead24a7784a?source=rss-d4e2bf391735------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ead24a7784a</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[http2]]></category>
            <dc:creator><![CDATA[Erik Witt]]></dc:creator>
            <pubDate>Fri, 17 Mar 2017 18:27:11 GMT</pubDate>
            <atom:updated>2017-03-21T10:11:45.546Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Hosting successful websites leaves you with a lot to take care of, from SSL encryption over CDN and browser caching to autoscaling server setups. Why not have <strong>someone else</strong> take care of all the hassle? This post will walk you through the simple 3-step process for fast, secure and scalable hosting on <a href="https://www.baqend.com/">Baqend</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zzL1rVaBWn7W7PDxobv6FQ.png" /></figure><p>Let’s start with the example of a recently announced website. In February, we got <a href="https://twitter.com/HesperMarkus/status/827432752551231488">asked on Twitter</a> to help out the <a href="https://twitter.com/search?q=%23everysecondcounts">#everysecondcounts</a> project, whose <a href="http://www.everysecondcounts.eu/">website</a> was struggeling under <strong>heavy load</strong>. The website is presenting videos from late night shows from <strong>all over the world</strong> in which the different people ironically address President Trump to convince him of their respective country being the second greatest country in the world — after the US.</p><h3>Baqend on Twitter</h3><p>Performance First: #everysecondcounts von @itsgreateu und @janboehm gibt&#39;s jetzt in schnell! #everymillisecondcounts https://t.co/HvJ2VklFS0</p><p>The heavy traffic after the announcement in various late night shows caused the website to break down multiple times. We stepped in and hosted the site under <a href="https://everymillisecondcounts.eu/old/">everymillisecondcounts.eu</a> on our platform which includes <strong>CDN backing</strong>, <strong>SSL encryption, caching </strong>and <strong>HTTP/2</strong>. This made the site <strong>much faster </strong>and resistant to the <strong>load spikes</strong>.</p><p><a href="https://everymillisecondcounts.eu/old/">Come to EU. It&#39;s huge. It&#39;s the greatest EU in the world!</a></p><h3>The Setup</h3><p>To show how to host your own website, let’s take the example of <a href="https://twitter.com/search?q=%23everysecondcounts">#everysecondcounts</a> and assume you want to create a website called <a href="https://everymillisecondcounts.eu/old/">everymillisecondcounts.eu</a>.</p><h4>0. Create an Account</h4><p>If you haven’t already, create a <a href="https://dashboard.baqend.com/register">free account</a> to start a Baqend app. In the background, a new autoscaling server setup is started, registered at the load balancer and connected to the CDN. The server and CDN automatically use various network optimizations and always set <strong>optimized cache-control headers</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0s2vIE1yJqFQl-_VEhF2lA.png" /><figcaption>Once the app is created, you can click on it to open your dashboard.</figcaption></figure><h4>1. File Upload</h4><p>The first thing you need to do is upload all your web assets. In the example, this is one HTML, one CSS and one JS file as well as a folder of images. You can upload the files in the <em>Files</em> category in your dashboard. Simply drag and drop everything into the predefined <em>www/</em> folder. For the entry point to work properly, make sure your main HTML file is named <em>index.html</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jwC0wvi6HCr4pAYMPDIr6Q.png" /><figcaption>Dashboard file explorer with uploaded assets.</figcaption></figure><p>For larger projects you may want to use the <a href="https://www.baqend.com/guide/#baqend-cli">Baqend CLI</a>, because it enables you to easily automate the deployment task with a script or deploy from the console.</p><p>After uploading all your files, you can access your website straight away under <a href="https://everymilisecondcounts.app.baqend.com/old/"><em>everymilisecondcounts.app.baqend.com</em></a></p><h4>2. Custom Domain</h4><p>The next step is to add your own domain. Let’s say you want to be found at <a href="http://www.everymillisecondcounts.eu./"><em>www.everymillisecondcounts.eu</em>.</a> Assuming you already own the domain, you now need to make sure it points to <em>everymilisecondcounts.app.baqend.com</em>. To achive this, you need to define a <strong>CNAME</strong> at your domain provider that looks like this (take a look at our Guide for <a href="https://www.baqend.com/guide/#deployment">more details</a>):</p><pre>www.everymillisecondcounts.eu.    IN CNAME everymilisecondcounts.app.baqend.com</pre><p>Now you have to tell your Baqend app about the new domain. To do that, navigate to <em>Settings &gt; Hosting </em>and then add the custom domain and press <strong>save</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kT01wuo3x8-elIx2UkQSiw.png" /><figcaption>Custom domain setup with DNS.</figcaption></figure><p>After a few seconds, your website can be accessed via the custom domain <a href="https://everymillisecondcounts.eu/old/"><em>www.everymillisecondcounts.com</em></a>. Now your website is online and the custom domain configured. This leaves you with one last step to go.</p><h4>3. SSL and HTTP/2</h4><p>To enable HTTPS and HTTP/2, click on the <strong><em>Request SSL Certificate</em></strong> button beside your domain. Now click on <em>validate domain</em>, to make sure the CNAME is set correctly. Finish the process by clicking on <strong><em>Activate SSL certificates</em></strong> and — that’s it! In a few minutes your site will be accessible via <a href="https://www.everymillisecondcounts.eu/"><strong>HTTPS</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHuyiVI9GDRX2KgRbnhEsw.png" /><figcaption>Almost done. Finish by clicking on <strong><em>Activate SSL certificates.</em></strong></figcaption></figure><p>Behind the curtains, Baqend generated a new SSL certificate using Let’s Encrypt, added it to a <strong>SAN Certificate</strong> and propagated it to the CDN for fast delivery. You will never have to <strong>renew your certificates</strong>, Baqend does that automatically for you.</p><p>To ensure that every visitor automatically uses HTTPS you can click on <strong><em>force SSL.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLi5HS4g_3CXb39rl_5Icw.png" /><figcaption>Successful HTTPS setup.</figcaption></figure><p>Now there is nothing left to do, except checking out <strong>how fast</strong> your website actually is.</p><h3>Performance Measurements &amp; Comparison</h3><p>There are many great tools that let you analyze your website performance like <a href="https://webpagetest.org/">WebPageTest</a>, <a href="https://developers.google.com/speed/pagespeed/">Google PageSpeed</a> or <a href="https://gtmetrix.com/">GTmetrix</a>. We like to use GTmetrix because of its <strong>extensive report features</strong> and good <strong>rendering</strong> <strong>performance</strong>. Running it from <strong>Vancouver, Canada </strong>(with our backend standing in Frankfurt, Germany), we get an inital load time of <strong><em>300–400 ms</em></strong> for our example website <a href="https://www.everymillisecondcounts.eu/old/">everymillisecondcounts.eu</a> (see <a href="https://gtmetrix.com/reports/www.everymillisecondcounts.eu/pROixfJl">GTmetrix report</a>). A more comprehensive overview is given by this timing table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCqcU7RB8wCebd9aOSpReQ.png" /><figcaption>Timing for everymillisecondcounts.eu measured with GTmetrix from Vancouver.</figcaption></figure><p>For the second visit of the website, all resources except for the HTML come from the browser cache so that the page loads virtually in an instant.</p><p>To put Baqend’s hosting performance into perspective, we also tried a few other common configurations offered by other hosters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VB5_HP31S_XoOMtA6IM6g.png" /><figcaption>All load times measured from Canada with GTmetrix.</figcaption></figure><ul><li>With <strong>standard hosting</strong> on Amazon S3 in Frankfurt (Germany) the avg. load time from the US is <strong>3,22s</strong> with HTTP.</li><li>Adding SSL to the S3-hosted version, the initial load time climbs to<strong> 4,03s</strong>.</li><li>Hosted on Baqend (also located in Frankfurt), the avg. page load time is cut down to <strong>440 ms</strong> for HTTP.</li><li>With TLS encryption enabled, avg. page load time goes down even further to <strong>350 ms</strong> because of the use of HTTP/2.</li></ul><p>These performance improvements translate very well to more complex and even dynamic websites, because Baqend also caches dynamic data such as complex database queries — without any staleness for clients. For a live comparison with other providers, see our performance shoot-out:</p><p><a href="http://benchmark.baqend.com/">Live Performance Shoot-out</a></p><p>The hosting setup discussed in this post optimizes network as well as backend performance. If you feel your frontend performance needs improvements, take a look at another our blogpost on the most important web-performance techniques:</p><p><a href="https://medium.baqend.com/building-a-shop-with-sub-second-page-loads-lessons-learned-4bb1be3ed07">Building a Shop with Sub-Second Page Loads: Lessons Learned</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YuPBwVsxt8mhBFgomWuNgg.png" /></figure><p>Our vision at Baqend is a <strong>web without load times</strong> and we want to give you the tools to achieve that.</p><p>Go ahead and try it for free at <a href="http://www.baqend.com/">www.baqend.com</a>.</p><p>Don’t want to miss our next post on web performance? Get it conveniently delivered to your inbox by joining our <a href="http://www.baqend.com/#newsletter">newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ead24a7784a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/baqend-blog/high-performance-website-hosting-with-ssl-and-http-2-made-simple-1ead24a7784a">High Performance Website Hosting with SSL and HTTP/2 Made Simple</a> was originally published in <a href="https://medium.com/baqend-blog">Speed Kit Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Shop with Sub-Second Page Loads: Lessons Learned]]></title>
            <link>https://medium.com/baqend-blog/building-a-shop-with-sub-second-page-loads-lessons-learned-4bb1be3ed07?source=rss-d4e2bf391735------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bb1be3ed07</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[wer-performance]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Erik Witt]]></dc:creator>
            <pubDate>Thu, 13 Oct 2016 08:39:12 GMT</pubDate>
            <atom:updated>2016-11-17T15:55:30.062Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Here is the story of how </em><a href="http://www.baqend.com/"><em>we</em></a><em> leveraged research on web-caching and NoSQL systems to prepare a </em><a href="https://thinks.baqend.com/"><em>webshop</em></a><em> for hundreds of thousands of visitors due to TV Show publicity and everything that we learned along the way.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8n8yIaSM7m7VflC3dOGr8g.png" /></figure><p>TV-Shows like “Shark Tank” (US), “Dragons’ Den” (UK) or “Die Höhle der Löwen (DHDL)” (GER) offer young startups a one-time opportunity to pitch their products to business magnates in front of a huge audience. The main profit, however, often does not lie in the strategic investments offered by jury members — <a href="http://www.bloomberg.com/news/articles/2014-07-15/shark-tank-do-two-thirds-of-deals-fall-apart">only few deals are finalized</a> — but rather in the attention raised during the show: a few on-air minutes can already draw hundreds of thousands of new visitors to a website and may boost the base level of activity for weeks, months or even permanently. That is, if the website can take the initial load spike and does not turn down user requests…</p><h3>Availability is not enough — latency is key!</h3><p>Webshops find themselves in a particularly tight spot, because they are not mere pastime projects (like, say, a blog), but are often backed by substantial investments from the founders themselves and <em>have to turn a profit</em>. The obvious worst case for a business is an overload situation during which the server has to drop user requests or even completely breaks down. And this is not as uncommon as you might think: About half of all webshops pitched in the current season of the DHDL became unreachable while in the spotlight. And staying online is only half the rent, since <strong>user satisfaction is hard-wired to the conversion rate</strong> and thus directly translates to the generated revenue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*bw_wf7Q8V_nykLwdnTA8wQ.png" /><figcaption><a href="http://infographicjournal.com/how-page-load-time-can-impact-conversions/">Source</a></figcaption></figure><p>There is an abundance of <a href="https://wpostats.com/tags/conversions/">studies</a> on the effect of page loading times on customer satisfaction and conversion rate to support this statement. For example, the Aberdeen Group discovered that a single second of additional latency results in 11% fewer page views and 7% loss in conversions. But you can also ask <a href="https://wpostats.com/2015/10/29/google-500ms.html">Google</a> or <a href="https://wpostats.com/2015/10/29/amazon-1-percent.html">Amazon</a> and they’ll tell you the same.</p><h3>How to speed up websites</h3><p>Building the webshop for the startup <a href="https://thinks.baqend.com/"><em>Thinks</em></a> — participating in DHDL, aired on September 6. — we faced the challenge to build a shop that can handle hundreds of thousands of visitors while constantly loading below one second. Here is what we learned in the process as well as from several years of database and web performance research.</p><p>There are three major drivers of page load time in state of the art web applications, all illustrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_z9Rbmp0GLNqr4LwWVCmQ.png" /></figure><ol><li><strong>Backend processing</strong>: The webserver needs time to load data from the database and to assemble the website.</li><li><strong>Network latency</strong>: Every request needs time to travel from the client to the server and back (request latency). This becomes even more essential when considering that an average website makes more than <a href="http://httparchive.org/interesting.php">100 request</a> to load completely.</li><li><strong>Frontend processing</strong>: The frontend device needs time to render the page.</li></ol><p>In order to speed up our webshop, lets address the three bottlenecks one by one.</p><h4>Frontend Performance</h4><p>The most important factor for frontend performance is the critical rendering path (<a href="https://developers.google.com/web/fundamentals/performance/critical-rendering-path/?hl=en">CRP</a>). It describes the 5 necessary steps in a browser to display the page to users, as illustrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1DEuTsfd9RckmywKDTwxGA.tiff" /><figcaption>Steps of the critical rendering path</figcaption></figure><ul><li><strong>DOM</strong>: When the browser parses the HTML, it incrementally generates a tree model of the HTML tags called <em>document object model</em> (DOM), which describes the content of the page.</li><li><strong>CSSOM</strong>: Once the browser receives all the CSS, it generates a tree model of the contained tags and classes called <em>CSS object model</em> with the styling information attached to the tree nodes. The tree describes how the page content is styled.</li><li><strong>Render Tree:</strong> By combining the DOM and CSSOM, the browser constructs a render tree, which contains the page content along with the styling information to apply.</li><li><strong>Layout:</strong> The layout step computes the actual position and size of the page content on the screen.</li><li><strong>Paint</strong>: The last step uses the layout information to paint the actual pixels to the screen.</li></ul><p>The individual steps are quite straight-forward; it’s the dependencies of steps that make things difficult and limit performance. The construction of the DOM and CSSOM usually have the greatest performance impact.</p><p>This diagram shows the steps of the critical rendering path including the wait-for dependencies as arrows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t40GwOqsIbif3WUxKGMRVQ.tiff" /><figcaption>Important dependencies in the critical rendering path</figcaption></figure><p>Before loading the CSS and constructing the full CSSOM nothing can be displayed to the client. Therefore CSS is called <strong>render blocking.</strong></p><p>JavaScript (JS) is even worse, because it can access and change both the DOM and CSSOM. This means that once a script tag in the HTML is discovered, the DOM construction is paused and the script is requested from the server. Once the script is loaded it cannot be executed before all CSS is fetched and the CSSOM is constructed. After CSSOM construction JS is executed, which as in the example below may access and alter the DOM as well as the CSSOM. Only then the construction of the DOM can proceed and the page can be displayed to the client. Therefore JavaScript is called parser blocking.</p><pre>Example of JavaScript accessing CSSOM and changing DOM:</pre><pre>&lt;<strong>script</strong>&gt;<br>   ...<br>   var old = elem.style.width;<br>   elem.style.width = &quot;50px&quot;;<br>   document.write(&quot;alter DOM&quot;);<br>   ...<br>&lt;/<strong>script</strong>&gt;</pre><p>And JS can even be more harmful than this. There are for example <a href="https://github.com/jjenzz/jquery.ellipsis">jQuery plugins</a> which access computed layout information of HTML elements and then start altering the CSSOM again and again until it agrees with the desired layout. As a consequence the browser has to repeat JS execution, render tree construction and layout over an over again before the user will see anything other than a white screen.</p><p>To optimize the CRP there are three <a href="https://developers.google.com/web/fundamentals/performance/critical-rendering-path/optimizing-critical-rendering-path">basic concepts</a>:</p><ol><li><strong>Reduce critical resources: </strong>Critical resources are those needed for the initial rendering of the page (HTML, CSS, JS files). These can be highly reduced by <strong>inlining</strong> CSS and JS needed for rendering the portion of the website visible without scrolling (called <strong>above the fold). </strong>Further JS and CSS should be loaded <strong>asynchronously</strong>. Files that cannot be loaded asynchronously can be <strong>concatenated</strong> into one file.</li><li><strong>Minimize bytes:</strong> The number of bytes loaded in the CRP can be highly reduced by <strong>minifying</strong> and <strong>compressing</strong> CSS, JS and images.</li><li><strong>Shorten CRP length:</strong> The CRP length is the maximum number of consecutive <strong>roundtrips</strong> to the server needed to fetch all critical resources. It is shortened both by reducing critical resources and minimizing their size (large files need multiple roundtrips to fetch). What further helps is to include <strong>CSS at the top</strong> of the HTML and <strong>JS at the bottom</strong>, because JS execution would block on fetching CSS and building the CSSOM and DOM anyway.</li></ol><p>Furthermore, <strong>browser caching</strong> is highly effective and should always be used. It fits in all three optimization categories because cached resources do not have to be loaded from the server in the first place.</p><p>The whole topic of CRP optimization is quite complex and especially inlining, concatenating and asynchronous loading can ruin code redability. Thankfully there are tons of great tools that will do these optimizations gladly for you, which can be integrated into your build and deployment chain. You should definitively take a look at the following tools for…</p><ul><li><strong>Profiling:</strong> <a href="https://gtmetrix.com/">GTmetrix</a> to measure page speed, <a href="https://www.webpagetest.org/">webpagetest</a> to profile your resources and Google’s <a href="https://developers.google.com/speed/pagespeed/insights/">PageSpeed Insights</a> to generate tips specific to your website on how to optimize your CRP.</li><li><strong>Inlining and optimization</strong>: <a href="https://github.com/addyosmani/critical">Critical</a> is great to automatically inline your CSS above the fold and load the rest asynchronously, <a href="https://github.com/Wildhoney/gulp-processhtml">processhtml</a> concatenates your resources and <a href="https://github.com/postcss/postcss">PostCSS</a> further optimizes CSS.</li><li><strong>Minification and compression:</strong> We use <a href="https://tinypng.com/">tiny png</a> for image compression, <a href="https://github.com/mishoo/UglifyJS">UglifyJs</a> and <a href="https://www.npmjs.com/package/cssmin">cssmin</a> for minification or <a href="https://developers.google.com/closure/">Google Closure</a> for JS optimization.</li></ul><p>With these tool and a little bit of work, you can build websites with great frontend performance. Here are the page speed test for a first visit for the <em>Thinks</em> shop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*zRwgmwVleajpoA-Xq4CjhQ.png" /><figcaption>Google page speed score for thinks.com</figcaption></figure><p>Interestingly, the only complaint in PageSpeed Insights is, that the Google Analytics script’s cache lifetime is too short. So Google is basicly complaining about itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ls8OEm_co28ib7ehy189rA.png" /><figcaption>First page load from Canada (GTmetrix), server hosted in Frankfurt</figcaption></figure><h4>Network Performance</h4><p>Network latency is the most important factor when it comes to page load time and it is also the hardest to optimize. But before we go into the optimizations, lets take a look at a breakdown of an initial browser request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3uwr-Q8L-OSH3ubXl-HiA.tiff" /></figure><p>When we type <a href="https://thinks.baqend.com/">https://thinks.baqend.com</a> into the browser and hit enter, the browser starts with a <strong>DNS lookup</strong> to identify the IP address associated with the domain. This lookup has to be done for every individual domain.</p><p>With the received IP address, the browser initiates a <strong>TCP connection</strong> with the server. The TCP handshake needs 2 roundtrips (1 with <a href="https://en.wikipedia.org/wiki/TCP_Fast_Open">TCP Fast Open</a>). With a secure <strong>SSL connection</strong> the TLS handshake needs an additional 2 roundtrips (1 with <a href="https://blogs.windows.com/msedgedev/2016/06/15/building-a-faster-and-more-secure-web-with-tcp-fast-open-tls-false-start-and-tls-1-3/#BqAGYfpLwoYCtE6i.97">TLS False Start</a> or <a href="https://timtaubert.de/blog/2014/11/the-sad-state-of-server-side-tls-session-resumption-implementations/">Session Resumption</a>).</p><p>After the initial connection, the browser sends the actual request and waits for data to come in. This <strong>time to first byte</strong> depends heavily on the distance between client and server and includes the time needed at the server to render the page (including session lookups, database queries, template rendering and so on).</p><p>The last step is <strong>downloading the resource</strong> (HTML in this case) in potentionally many roundtrips. Especially new connections often need a lot of roundtrips because the initial congestion window is small. That means TCP does not use the full bandwidth right from the start but increases it over time (see <a href="https://en.wikipedia.org/wiki/TCP_congestion_control">TCP congestion control)</a>. The speed is subject to the slow-start algorithm that doubles the number of segments in the congestion window per round-trip until packet loss occurs. On mobile and Wifi networks lost packets hence have a large performance impact.</p><p>Another thing to keep in mind: with HTTP/1.1 you only get <strong>6 parallel connections </strong>(2 if browsers would still follow the orginal standard). Thus, you can only request up to 6 resources in parallel.</p><p>To get an intuition of how important network performance is for page speed the <a href="http://httparchive.org/interesting.php">httparchive</a> has a lot of statistics. For example the average website loads about 2.5 MB of data in over 100 requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ycpDPIWtye5aFu7Kdtb5Ew.png" /><figcaption><a href="http://httparchive.org/interesting.php#reqTotal">source</a></figcaption></figure><p>So websites make a lot of small requests to load many resources, but network bandwidth is increasing all the time. The evolution of physical networks will save us, right? Well, not really…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1NZ69zvARAdY6fkf2ljng.tiff" /><figcaption>From <a href="https://hpbn.co/">High Performance Browser Networking</a> by Ilya Grigorik</figcaption></figure><p>It turns out that increasing <strong>bandwidth</strong> beyond 5 Mbps does not really have an effect on page load time at all. But decreasing <strong>latency</strong> of individual requests drives down page load time. That means doubling the bandwidth leaves you with the same load time, while cutting in half latency will give you half your load time.</p><p>So if latency is the deciding factor for network performance what can we do about it?</p><ul><li><strong>Persistent connections</strong> are a must-have. There is nothing worse than when your server closes the connection after every request and the browser has to perform handshakes and TCP slow start again and again.</li><li><strong>Avoid redirects</strong> wherever possible as they slow down your initial page load a lot. Always link the full url (www.thinks.com as apposed to thinks.com) for example.</li><li>Use <strong>HTTP/2</strong> if possible. It comes with <strong>server push</strong> to transfer multiple resource for a single request, <strong>header compression </strong>to drive down request and response sizes and also request <strong>pipelining</strong> and <strong>multiplexing</strong> to send arbitrary parallel request over a single connection. With server push, your server can for example ship your html and push CSS and JS needed by the website right after that without waiting for the actual request.</li><li>Set explicit <strong>caching headers</strong> for your static resources (CSS, JS, static images like logos). This way you can tell the browser how long to cache these resources and when to revalidate. Caching can potentially save you a lot of roundtrips and bytes to download. If no explicit headers are set, the browser will do <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html">heuristic caching</a>, which is better than nothing but far from optimal.</li><li>Use a <strong>Content Delivery Network</strong> (CDN) to cache images, CSS, JS and HTML. These distributed cache networks can significantly reduce the distance to your users and thus deliver resources much faster. They also speed up your initial connection since you do the TCP and TLS handshakes with a nearby CDN node, which in turn has warm and persistent backend connections.</li><li>Consider building a <strong>Single-Page App</strong> with a small initial page that loads additional parts asynchronously. This way you can use cachable HTML templates, load dynamic data in small requests and only update sections of the page during navigation.</li></ul><p>In summary, there are a few do’s and don’ts when it comes to network performance but the limiting factor is always the number of roundtrips combined with the physical network latency. The only effective way to conquer this limitation is to bring data closer to clients. State of the art web caching does exactly that but is only applicable for static resources.</p><p>For <em>Thinks,</em> we followed the above guidelines, used the <a href="https://www.fastly.com/">Fastly</a> CDN and aggressive browser caching even for dynamic data using a novel <a href="https://medium.baqend.com/bringing-web-performance-to-the-next-level-an-overview-of-baqend-be3521bc2faf#.ajhyivndc">Bloom Filter algorithm</a> to keep cached data consistent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*djg5dkELtzm0wQd_sKmoTg.tiff" /><figcaption>Repeated load of <a href="https://thinks.baqend.com/">https://thinks.baqend.com</a> showing the browser cache coverage</figcaption></figure><p>The only requests for a repeated page load that are not served from browser cache (see figure above) are two async calls to Google’s analytics API and the request for the initial HTML that is fetched from the CDN. As a consequence, the page loads instantly for repeated page loads.</p><h4>Backend Performance</h4><p>For backend performance, we need to consider both latency and throughput. To achieve low latency, we need to minimize the processing time of the server. To sustain high throughput and cope with load spikes, we need to adopt a <strong>horizontally scalable</strong> architecture. Without going into too much detail — the space of design decisions impacting performance is huge — these are the most important components and properties to look for:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lF1D54UVWbHPosMZBoCJSg.tiff" /><figcaption>Components of a scalable backend stack: load balancers, stateless application servers, distributed databases</figcaption></figure><p>First of all, you need <strong>load balancing</strong> (e.g. Amazon ELB or DNS load balancing) to assign incoming requests to one of your application servers. It should also implement <strong>automatic scaling</strong> to spawn additional application servers when needed as well as <strong>failover</strong> to replace broken servers and re-route requests to healthy ones.</p><p><strong>Application servers</strong> should <strong>minimize shared state</strong> to keep coordination to a minimum and use <strong>stateless session handling</strong> to enable free load balancing. Furthermore, the server should be <strong>efficient</strong> in code as well as IO to minimize server processing time.</p><p><strong>Databases</strong> also need to withstand load spikes and impose as little processing time as possible. At the same time, they need to be expressive enough to model and query data as needed. There are tons of scalable databases (especially NoSQL) each with its own set of trade-offs. For more details, see our survey and decision guidance on this topic:</p><p><a href="https://medium.baqend.com/nosql-databases-a-survey-and-decision-guidance-ea7823a822d">NoSQL Databases: a Survey and Decision Guidance</a></p><p>The <em>Thinks</em> webshop is built on <a href="http://www.baqend.com/">Baqend</a>, which using the following backend stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C7yp3ODTiIyCv6ZxtZVQCg.tiff" /><figcaption>Baqend’s backend stack: MongoDB as the main database, stateless application servers, HTTP caching hierarchy, REST and the JS SDK for the web frontend</figcaption></figure><p>The main database used for <em>Thinks</em> is <strong>MongoDB.</strong> To maintain our expiring Bloom filter (used for browser caching), we use <strong>Redis</strong> for its high write thoughput. The stateless application servers (<a href="http://orestes.info/assets/files/Paper.pdf"><strong>Orestes Servers</strong></a>) provide interfaces to backend features (file hosting, data storage, real-time queries, push notifications, access control, etc.) and handle cache coherence for dynamic data. They get their requests from the <strong>CDN</strong>, which also acts as a load balancer. The website frontend uses a <strong>JS SDK</strong> based on a <strong>REST API</strong> to access the backend which automatically leverages the full <strong>HTTP caching hierarchy </strong>to accelerate requests and keep cached data up-to-date.</p><h4>Load Testing</h4><p>To test the <em>Thinks</em> webshop under high load, we conducted a load test with 2 application servers on t2.medium AWS instances in Frankfurt. MongoDB ran on two t2.large instances. The load test was built using <a href="http://jmeter.apache.org/">JMeter</a> and executed on 20 machines on <a href="http://www.softlayer.com/">IBM soft layer</a> to simulate <strong>200.000 users</strong> accessing and surfing through the website within <strong>15 minutes</strong>. 20% of the users (40.000) were configured to execute an additional payment process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTn0h56pvC5HYEAaEPnI1A.png" /><figcaption>The load test setup for the webshop</figcaption></figure><p>We discovered a few bottlenecks in our payment implementation, for example we had to switch from an optimistic update of the stock (implemented with <a href="https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/">findAndModify</a>) to MongoDB’s partial update operations (<a href="https://docs.mongodb.com/manual/reference/operator/update/inc/"><em>inc</em></a><em>). But after that the servers handled the load just fine achieving an average request latency of 5 ms.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*SrfTDYzeTKh5-T26I2Nakw.tiff" /><figcaption>JMeter output during the load test: 6.8 million requests in 12 minutes, 5 ms average latency</figcaption></figure><p>All the load tests combined generated about <strong>10 million request</strong> and tranfered <strong>460 GB of data</strong> with a CDN <strong>cache hit rate</strong> of <strong>99.8%</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buvg1l0A2FrzqR8dbgQ5cQ.png" /><figcaption>The dashboard overview after the load test</figcaption></figure><h3>Summary</h3><p>In summary, good user experience rests on three pillars: frontend, network and backend performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KaPvIFl16OLU76KxJMR1WQ.tiff" /></figure><p><strong>Frontend performance</strong> is the easiest to achieve in our opinion because there is already great tooling and a bunch of best practices that are easy to follow. But still a lot of websites do not follow these best practices and do not optimize their frontend at all.</p><p><strong>Network performance</strong> is the most important factor for page load times and also the hardest to optimize. Caching and CDNs are the most effective ways of optimization but come with a considerable effort even for static content.</p><p><strong>Backend performance</strong> is dependent on single-server performance and your ability to distribute work across machines. Horizontal scalability is particularly difficult to implement and has to be considered right from the start. A lot of projects treat scalability and performance as an afterthought and come into big trouble when their business grows.</p><h3>Literature and Tool Recommendations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fu5eAxBQORO1em86kuJBgA.tiff" /></figure><p>There are great books on the topic of web performance and scalable systems’ design. <a href="https://hpbn.co/">High Performance Browser Networking</a> by Ilya Grigorik contains almost everything you need to know about networking and browser performance, plus the constantly updated version is free to read online! <a href="http://dataintensive.net/">Desining Data-Intensive Applications</a> by Martin Kleppmann is still in early release state but already among the best book in its field. It covers most fundamentals behind scalable backend systems with great detail. <a href="http://designingforperformance.com/">Designing for Performance</a> by Lara Callender Hogan is all about building fast websites with great user experience covering a lot of best practices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNqMUe5C9Z2KvCjqQJRNrA.tiff" /></figure><p>There are also great online guides, tutorials and tools to consider. From the beginner-friendly Udacity course <a href="https://www.udacity.com/course/website-performance-optimization--ud884">Website Performance Optimization</a> over Google’s <a href="https://developers.google.com/web/fundamentals/performance/?hl=en">developer performance guide</a> to profiling tools like <a href="https://developers.google.com/web/fundamentals/performance/?hl=en">Google PageSpeed Insights</a>, <a href="https://gtmetrix.com/">GTmetrix</a> and <a href="https://www.webpagetest.org/">WebPageTest</a>.</p><h3>Newest Developments In Web Performance</h3><p><strong>Accelerated Mobile Pages</strong></p><p>Google is doing a lot to increase awareness for web performance with projects such as <a href="https://developers.google.com/speed/pagespe%E2%80%A6">PageSpeed Insights</a>, <a href="https://developers.google.com/web/fundamentals/performance/">developer guides</a> for web performance and including page speed as a leading factor of their <a href="https://webmasters.googleblog.com/2010/04/using-site-speed-in-web-search-ranking.html">page rank</a>.</p><p>Their newest concept to improve page speed and user experiance in Google search is called <a href="https://www.ampproject.org/">accelerated mobile pages (<strong>AMP</strong>)</a>. The idea is to have news articles, product pages and other search content load instantly right from the Google search. To this end, these pages have to be built as AMPs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*dFufupcLXGvhJdeqhntcsA.png" /><figcaption>Example of an AMP page</figcaption></figure><p>AMP does two major things:</p><ol><li>Websites built as AMP use a stripped-down version of HTML and use a JS loader to render fast and load as much resources as possible asynchronously.</li><li>Google caches the websites in the Google CDN and delivers them via HTTP/2.</li></ol><p>The first means in essence, AMP restricts your HTML, JS and CSS in a way that pages built this way have an optimized critical rendering path and can easily be crawled by Google. AMP enforces <a href="https://www.ampproject.org/docs/reference/spec">several restrictions</a>, for example all CSS must be inlined, all JS must be asynchronous and everything on the page must have a static size (to prevent repaints). Although you can achieve the same results without these restrictions by sticking to the web performance best practices from above, AMP might be good trade-off and help for very simple websites.</p><p>The second means that Google crawls your website and then caches it in the Google CDN to deliver it very fast. The website content is updated once the crawler indexes your website again. The CDN also respects static TTLs set by the server but performs at least <a href="https://developers.google.com/amp/cache/overview#google-amp-cache-updates">micro-caching</a>: resources are considered fresh for at least one minute and updated in the background when a user request comes in. The effective consequence is that AMP is best applicable in use cases where the content is mostly static. This is the case for news websites or other publications that are only changed by human editors.</p><h4>Progressive Web Apps</h4><p>Another approach (also by Google) are <a href="https://developers.google.com/web/fundamentals/getting-started/codelabs/your-first-pwapp/">progressive web apps</a> (<strong>PWA</strong>). The idea is to cache static parts of a website using <a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers">service workers</a> in the browser. As a consequence, these parts load instantly for repeated views and are also available offline. Dynamic parts are still loaded from the server.</p><p>The <em>app shell </em>(the single page application logic) can be revalidated in the background. If updates to the app shell are identified, the user is prompted with a message asking him to update the page. This is for example done in <a href="https://www.google.de/inbox/">Inbox by Gmail</a>.</p><p>However, the service worker code caching static resources and doing the revalidation comes with considerable effort for every website. Furthermore, only Chrome and Firefox support Service Workers sufficiently.</p><h3>Caching Dynamic Content</h3><p>The problem that all the caching approaches suffer from is that they cannot deal with dynamic content. This is simply due to how HTTP caching works. There are two types of caches: <strong>Invalidation-based</strong> caches (like forward proxy caches and CDNs) and <strong>expiration-based</strong> caches (like ISP caches, corporate proxies and <strong>browser caches</strong>). Invalidation-based caches can be invalidated proactively from the server, expiration-based caches can only be revalidated from the client.</p><p>The tricky thing when using expiration-based caches is that you must specify a cache lifetime (TTL) when you first deliver the data from the server. After that you do not have any chance to kick the data out. It will be served by the browser cache up to the moment the TTL expires. For static assets it is not such a complex thing, since they usually only change when you deploy a new version of your web application. Therefore, you can use cool tools like <a href="https://github.com/smysnk/gulp-rev-all">gulp-rev-all</a> and <a href="https://github.com/yeoman/grunt-filerev">grunt-filerev</a> to hash the assets.</p><p>But what do you do with all the data which is loaded and changed by your application at runtime? Changing user profiles, updating a post or adding a new comment are seemingly impossible to combine with the browsers cache, since you cannot estimate when such updates will happen in the future. Therefore, caching is just disabled or very low TTLs are used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K1ZJfaJ6zgz6eEk_.png" /><figcaption>Example of how cached dynamic data becomes outdated when updated by another client</figcaption></figure><h4>Baqend’s Cache-Sketch Approach</h4><p>At <a href="http://www.baqend.com/">Baqend</a>, we have researched and developed an approach to check the staleness of a URL in the client before actually fetching it. At the begin of each user session, we fetch a very small data structure called Bloom filter, which is a highly compressed representation of the set of all stale resources. By looking in the Bloom filter, the client can check whether a resource might be stale (contained in the Bloom filter) or is definitely fresh. For potentially stale resources, we bypass the browser cache and fetch the content from the CDN. In all other cases, we serve the content directly from the browsers cache. Using the browser cache saves network traffic, bandwidth and is <em>fast</em>.</p><p>In addition, we ensure that the CDN (and other invalidation-based caches like Varnish) always contain the most recent data by instantly purging resources as soon as they become stale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lpjUnI1olugLyyto.png" /><figcaption>Example of how Baqend ensures the freshness of cached dynamic data</figcaption></figure><p>The <a href="http://de.slideshare.net/felixgessert/bloom-filters-for-web-caching-lightning-talk">Bloom filter</a> is a probabilistic data structure with a tunable false positive rate, which means that the set may indicate containment for objects which were never added, but will never drop an item that actually was. In other words, we may occasionally revalidate fresh resources, but <strong>we never deliver stale data</strong>. Note that the false positive rate is very low and it is what enables us to make the footprint of the set very small. For an example we just need 11Kbyte to store 20,000 distinct updates.</p><p>There is lot of stream processing (query match detection), machine learning (optimal TTL estimation) and distributed coordination (scalable Bloom filter maintenance) happening at the server side. If you’re interested in the nitty-gritty details have a look at this <a href="http://www.baqend.com/paper/btw-cache.pdf">paper</a> or <a href="http://de.slideshare.net/felixgessert/talk-cache-sketches-using-bloom-filters-and-web-caching-against-slow-load-times">these slides</a> for a deep-dive.</p><h4>Performance Gains</h4><p>What it all boils down to is this.</p><blockquote>Which page speed improvement can be achieved with Baqend’s caching infrastructure?</blockquote><p>In order to showcase the benefit of using Baqend, we built a very simple news application on each of the leading competitors in the backend-as-a-service (BaaS) space and measured the page load times from different locations all over the world. As shown below, Baqend consistently loads below 1 second and is 6.8 times faster than the competition on average. Even when all clients come from the same location the server is located, Baqend is 150% faster due to browser caching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wT5diC6Pcd95wUSVroYviw.tiff" /><figcaption>Average load time comparison for a simple news application</figcaption></figure><p>We built this comparison as a <a href="http://benchmark.baqend.com/">hands-on web app</a> to compare the BaaS competition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2Gc9KCtG_33mRe5Q9ayJw.tiff" /><figcaption>Screenshot of the <a href="http://benchmark.baqend.com/">hands-on comparison</a></figcaption></figure><p>But this is of course a test scenario and not a web application with real users. So lets come back to the <em>Thinks</em> webshop to look at a real world example.</p><h3>Thinks Webshop — All The Facts</h3><p>When DHDL (german version of “Shark Tank”) aired on september 6th with 2.7 million viewers, we were sitting in front of the TV and our Google analytics screens, excited for the the <em>Thinks</em> founders to present their product.</p><p>Right from the start of their presentation, the number of concurrent users on the webshop rapidly increased to about 10.000, but the real bump happend at the commercial break when suddenly over 45.000 concurrent users came to visit the shop to buy a Towell+:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*sCsJOCw-7clmfIbyYRwUrA.gif" /><figcaption>Google analytics measurement starting right before the commercial break.</figcaption></figure><p>During the 30 minutes <em>Thinks</em> was on the air, we got <strong>3.4</strong> million requests, <strong>300.000</strong> visitors, up to <strong>50.000</strong> concurrent visitors and up to 20.000 requests per second — all this achieving a <strong>cache hit rate of 98.5%</strong> at CDN level and an average <strong>server CPU load of 3%</strong>.</p><p>As a consequence, the <strong>page load time </strong>was<strong> below 1 second</strong> for the whole time enabling a great <strong>conversion rate of 7.8%</strong>.</p><p>If we take a look at the other shops presented in the same episode of DHDL, we see that four of them where <strong>completely down</strong> and the remaining shops only leveraged few performance optimizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*3VLcWgaWIiFlJdaqy27gCg.png" /><figcaption>Overview of availability and Google page speed score of the shops presented a DHDL on September 6th.</figcaption></figure><h3>Summary</h3><p>We have seen the bottlenecks to overcome when designing fast and scalable websites: we have to master the <strong>critical rendering path</strong>, understand the network limitations, the importance of <strong>caching</strong> and design for <strong>horizontal scalability</strong> in the backend.</p><p>We have seen a lot of tools solving individual problems as well as accelerated mobile pages (<strong>AMP</strong>) and progressive web apps (<strong>PWA</strong>) taking a more comprehensive approach. Still, the problem of <strong>caching dynamic data</strong> remained.</p><p><strong>Baqend</strong>&#39;s approach is to reduce web development to building mostly the frontend and using backend features of Baqend’s fully managed cloud service through a JS SDK, including data and file storage, (realtime-) queries, push notifications, user management and OAuth as well as access control. The platform automatically accelerates all request by using the full HTTP cache hierarchy and guarantees availability as well as scalability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*lDR0ZIX0ACdKwYMzEqyAKg.png" /></figure><h4>Our vision at Baqend is a web without load times and we want to give you the tools to achieve that.</h4><p>Go ahead and try it for free at <a href="http://www.baqend.com/">www.baqend.com</a>.</p><p>Interesting discussion of this article on <a href="https://news.ycombinator.com/item?id=12774277">Hacknews</a>.</p><p>Don’t want to miss our next post on web performance? Get it conveniently delivered to your inbox by joining our <a href="http://www.baqend.com/#newsletter">newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bb1be3ed07" width="1" height="1" alt=""><hr><p><a href="https://medium.com/baqend-blog/building-a-shop-with-sub-second-page-loads-lessons-learned-4bb1be3ed07">Building a Shop with Sub-Second Page Loads: Lessons Learned</a> was originally published in <a href="https://medium.com/baqend-blog">Speed Kit Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>