What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.
Cloud Services / Software Development

Serve Dynamic Content to Millions of Users at No Cost

Nandi Wong, a Senior Backend Engineer at KintoHub, recently combined the right developer tools to build a dynamic website that serves millions of users at no cost. Not to mention, it was built in only two days.
Feb 26th, 2020 3:00am by
Featued image for: Serve Dynamic Content to Millions of Users at No Cost

Joseph Cooper
Joseph Cooper's been coding since the age of nine, founded or partnered in three profitable gaming startups and published a paper about optimizing signs and maps in virtual worlds. Most recently, Joseph led infrastructure, mobile, and product engineering teams at Junglee Games from a 50K USD MRR business to 5M USD MRR and 300+ employees in 4 years. Taking a break from gaming, Joseph is building KintoHub, an all-in-one platform to intuitively manage databases, backend services, cron jobs, websites and more on any cloud.

Creating scalable content for today’s massively connected world can come packed with many surprises. Everything from an insane Amazon Web Services bill, exhausted infrastructure teams scrambling to handle high demand or an individual developer sleeping soundly serving millions of users without having to enter in a single credit card number. Everyone wishes to be the latter but usually did not know such a solution exists in the rapidly evolving software community.

The Cloud Native Computing Foundation (CNCF) keeps everyone informed on the too many options we have to face when making next-gen infrastructure-related decisions and it has become a running joke on the abundance of JavaScript frameworks and methodologies we should be using to build software.

It doesn’t have to be this complicated. As an example, Nandi Wong, a Senior Backend Engineer at KintoHub, recently combined the right developer tools to build a dynamic website that serves millions of users at no cost. Not to mention, it was built in only two days.

WARS’ initial goal was to aggregate and inform the general public about everything from hospital queues, stores taking advantage of upselling medical supplies and alerts on neighborhoods that are being impacted by the Corona Virus. Data is publicly available across numerous sources on the web in formats from PDF, HTML websites and some public APIs and requires some processing to extract the exact information so it may be redistributed in a simple format. The team wanted to do update this information every few minutes, especially since a lot of the data is time-sensitive.

In order to serve content to millions of users, without incurring any costs, you must get rid of as many infrastructure dependencies as possible. Most software engineers may think that databases and backend APIs are required for serving dynamic content to consumers. Not anymore! Instead of building a stack that combines horizontal scaling services, data scraping cronjobs, Kubernetes, caching with Redis, CDNs, and databases at a heavy cost to develop and scale, WARS used static website generators and a next-generation cloud environment to scale at no cost.

Introducing Static Website 2.0

The first tool chosen was Gatsby, a widely adopted static website generator. The idea behind static websites is being able to quickly generate content for marketing, company, documentation or product information without having to run a web server. Wait?! Serving a website without a server… are you talking about serverless? No!

CDNs bring the content locally to your users to serve content faster

Cloudflare can host your static website files on hundreds of servers across the internet. The concept has been around for a while and is known as a Content Delivery Network (CDN) which all cloud providers provide their own flavor. Cloudflare offers an almost infinitely free tier that happily serves your files as long with very few limitations. You still will need an origin server that provides the initial content that gets distributed globally, which usually is hosted for free on Github Pages or other website providers.

Gatsby can be configured to programmatically generate static websites at build-time. Using GraphQL, it can query various sources such as a backend API or raw JSON files to compile a data set that will be used when rendering the HTML files at build time. Once the files are rendered with the correct data, they are saved as HTML/Javascript/CSS in a single folder which can be served online. The challenge with WARS comes with how to launch a cost-effective website with data that isn’t static…

The Dilemma of Serving Dynamic Content

Since WARS requires the data to be updated every few minutes, this usually discounts static websites as an option. Traditionally when a user loads the page, one or many API calls will be made to a backend server to grab the data and insert it into the page before rendering the result for every unique user! Usually, data resides in a database, be it MongoDb, Mysql, Postgres, etc. The source of the data is to be populated by another service that is legally scraping the latest information from various sources. Combining all of this, it would take some time to develop, test and build on the cloud of your choice.

Trigger new deployments every few minutes to generate static results globally!

Using automation combined with the concept of static website generators, you can regenerate the website with the data you want to serve every few minutes. This means a build is triggered and deployed constantly to Cloudflare. This approach only works when all users view a single source of generated content. If users are looking at specific contextual content, such as their account balance, this approach would not work.

Combine and Simplify All Cloud Operations

KintoHub was chosen to help with automation and hosting as an all-in-one platform for websites, cronjobs, databases and backend services. It picks up code from Github, hosts a free static website with Let’s Encrypt SSL with Cloudflare CDN support and makes it easy to build and repeatedly trigger Cron Job operations that force regenerating and deploying WARS.  Under the hood is really Kubernetes and Dockerfiles orchestrated by a simple UI/UX dashboard, but the time to release the idea of WARS was sped up by a lot due to not having to configure all the moving parts on Amazon, Google, Azure or Kubernetes itself.

Two Cronjobs and one Gatsby Website made easy with KintoHub DEV and `PROD environments

In Conclusion

Today the world is riddled with too many options and if you’re not learning hourly, testing new technologies nor evolving with the latest trends; your next project may incur higher costs or slower go to market times. Open source has revolutionized the world in how we collaborate and share features and functionality. As the software industry moves forward, businesses and individuals need to figure out how to easily integrate the power of the widely available options to be more clear and instantaneously useful.

Hopefully, the following links can be helpful in the never-ending exploration of that journey.

  1. Get Started with Gatsby
  2. Get Started with Kintohub
  3. WARS repo on Github
  4. WARS website

The Cloud Native Computing Foundation is a sponsor of The New Stack.

Feature image via Pixabay.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: The New Stack.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.