Need to save something? Use an API.
Need to retrieve some data? Use an API.
Anything that would traditionally be done by a backend server is abstracted away into an API. This lets you build parts of the application out of simple microservices and offload parts you don’t want to build or maintain to third-party services. Which APIs you want to use will depend on your specific use-case. Some parts of the application are time-consuming to build and maintain, so I would offload those to dedicated services. This would also be a good place to use a service like AWS Lambda for the parts of the application that do need some custom code that can’t run in the user’s browser.
Markup is a general term for templates or pre-compiled static content. In a traditional application architecture pages are generated dynamically using a language like PHP. In a JAMstack application the pages are fully or mostly already generated and are stored as static HTML or template files. This way they can be served easily and instantly from the cloud without worrying about an application server.
There are many different way you can do this. Here are a couple:
- Use a static site generator like Jekyll. A static site generator can compile a bunch of markup or text files into static HTML files.
These are not strictly required for JAMstack applications, but they are highly recommended practices.
It is highly recommended that you serve your static content files from a CDN. A CDN serves your site from whichever server the visitor is closest to. This gives you much better site response times.
Sample application architecture
Let’s take a look at how we might build a blog using this stack. Here are the core technologies I would use for this:
- Jekyll is a great tool that lets you generate static HTML out of a variety of formats. You can generate web pages out of plain text, Markdown language, Textile markdown language, etc.
- Amazon CloudFront can store and serve the generated HTML to users around the world rapidly. It can also handle large surges in traffic easily so scale won’t be an issue.
- Algolia provides Search as a Service. Using their API you can have high-quality article search results without needing a server or database.
- Facebook Comments lets you have comments on the site without managing a backend service or user system. Over two billion people use Facebook so it is a natural choice because people will comment more if they don’t need to make a new account to do it.
Using this architecture you can write your articles in plain text or a markdown language, compile the articles into static HTML pages, store the pages in the cloud, and offload users, comments, and search for other people to maintain and develop. That makes everything easy to maintain, host, and develop. I will have to switch this site over to JAMstack in the future!