Contentstack is a SaaS-based, headless content management platform that stores and manages content in the cloud. This setup enables users to retrieve and deliver content to any channel (web, mobile, devices, etc.) via Contentstack's Content Delivery APIs.
Contentstack provides a Node.js-based web application framework “contentstack-express” for building websites with push-publishing. This framework lets you save the content that you publish via Contentstack in the local file system of a web server. Subsequently, for every incoming page request on the website, the content is retrieved and rendered directly from the local storage, instead of fetching it from Contentstack database via APIs.
Let’s see how you can set up your server architecture based on this structure.
In this architecture, you connect all your servers to Contentstack database but sync your content with only one web server. Here’s the diagrammatic representation of this architecture.
This architecture too has its own set of pros and cons.
Next, we will see how to set up the web servers using a process management app.
When setting up the ‘Single sync in multiple servers’ architecture, you need to make sure that you set one server to run on default configuration (SYNC=true) and on a different port, for example, 8000.
PORT=8000 node app.js
set PORT=8000; node app.js
This server will connect with Contentstack’s real-time servers and sync (i.e., read/write on storage) the published, unpublished, and deleted contents. Only this server will be able to write on the database.
On the other hand, the rest of the servers will run on another port and with their ‘SYNC’ environment variable set to ‘false’.
SYNC=false PORT=4000 node app.js
SYNC=false; PORT=4000; node app.js
This server will only be serving data (i.e., only read from database)