Skip to content

Expert · Deployment and scaling · topic 49 of 54 · 30 min

Deploying to the cloud

Explanation

The cloud means renting computers, databases and storage from a company like AWS, Google Cloud or Azure, and paying for what you use. You can rent bare servers (IaaS), give your code to a platform that runs it (PaaS), or run small functions only when called (serverless). A real deploy also needs a domain, HTTPS, production environment variables, a plan for zero-downtime releases and a budget alert.

What "the cloud" is

The cloud is other people's computers in big buildings called data centres, rented over the internet. Instead of buying a server for lakhs of rupees, you rent one by the hour and can switch it off any time. Cloud companies also rent ready services: databases, file storage, queues and more, so you do not have to run them yourself.

Think of it like this: Think of getting around a city. Buying your own car is like owning servers: full control, but you pay for repairs and parking. Renting a self-drive car is IaaS: you get a car, but you drive and fill fuel. Booking a cab with a driver is PaaS: you say where to go, they handle the driving. An auto-rickshaw for one short trip is serverless: you pay only for that ride.
ModelYou manageProvider managesExamples
IaaS (Infrastructure as a Service)OS updates, runtime, app, scalingHardware, network, data centreAWS EC2, Google Compute Engine, Azure VMs
PaaS (Platform as a Service)Your code and settingsServers, OS, runtime, often HTTPS and scalingRender, Railway, Fly.io, Heroku, Google App Engine
Serverless functionsSmall functionsEverything else; runs only when calledAWS Lambda, Google Cloud Run functions, Azure Functions, Vercel Functions

The big clouds and their Indian regions

A region is a group of data centres in one area. Picking a region near your users makes the app faster, and some Indian rules (for example the RBI rule on payment data) require certain data to be stored in India.

CloudRegions in India
AWS (Amazon Web Services)Mumbai (ap-south-1), Hyderabad (ap-south-2)
Google CloudMumbai (asia-south1), Delhi (asia-south2)
Microsoft AzureCentral India (Pune), South India (Chennai), West India (Mumbai)

For a first project, simpler platforms like Render, Railway or Fly.io are often easier: connect your GitHub repo, set environment variables, and they build and run it with HTTPS. Use a managed database too (for example Amazon RDS, Google Cloud SQL, Neon or Supabase for Postgres): the provider handles backups, updates and failover, which are hard to do well yourself.

Domain, DNS and HTTPS

A domain is your name on the internet, like api.example.in, bought from a registrar for a yearly fee. DNS (Domain Name System) is the internet's phone book: it turns that name into the address of your server. You add records at your DNS provider: an A record points a name to an IPv4 address, a CNAME points a name to another name (common with platforms), and a TXT record holds text used to prove you own the domain.

bash
dig +short api.example.in             # which address does this name point to?
sudo certbot --nginx -d api.example.in # get a free Let's Encrypt certificate for nginx
curl -I https://api.example.in/healthz  # check HTTPS works and see the response headers
On your own server with nginx. Platforms like Render or Fly.io do the certificate part for you.

HTTPS encrypts traffic between users and your server so nobody on the Wi-Fi can read passwords or OTPs. It needs a certificate. Let's Encrypt gives free certificates that last only a short time (90 days, and planned to get shorter), so renewal must be automatic. Certbot sets up that renewal for you.

Environment variables in production

In production, settings like DATABASE_URL, REDIS_URL and payment keys come from environment variables set in the platform's dashboard or a secret manager, never from a file in git. Check at startup that every required variable is present, and stop with a clear message if one is missing. Failing fast at boot is far better than failing on the first real payment.

Zero-downtime deploys

  1. Start the new version next to the old one.
  2. Wait until its health check (for example GET /healthz) answers 200.
  3. Move traffic to the new version, a few servers at a time (a rolling deploy) or all at once to a ready copy (blue-green).
  4. Stop the old version only after the new one is healthy. If the new one fails, traffic never moves, and rollback is instant.
  5. Make database changes backward compatible: first add a new column, deploy code that uses it, and remove the old column in a later release.
Careful: Cloud bills can surprise you: a forgotten large server, a database left running after a test, or heavy data transfer. Set a budget alert on day one, delete what you do not use, and remember that free tiers and their limits change often. Check the provider's current pricing page, not an old blog post.
Tip: Keep a written deploy checklist and follow it every time, even for "tiny" changes. Most outages come from steps people skip when they are in a hurry.

Watch the lesson

Deploying to the cloud · 1/7

Deploying to the cloud

The cloud means renting computers and services by the hour instead of buying them.

Prefer a video by a teacher? Find free videos on “how to deploy node js api to cloud for beginners” on YouTube ↗

In real life: Launching a coaching institute's test series app

A developer in Kota builds an online test series API. For launch she picks a PaaS in the Mumbai region close to her students, a managed Postgres with daily backups, and a domain with a CNAME pointing to the platform, which issues the HTTPS certificate automatically. DATABASE_URL and the payment keys are set in the dashboard, and the app refuses to start if one is missing. Each deploy starts the new version, waits for /healthz, then switches traffic, so students taking a test at 9 pm never see an error. A budget alert at 3,000 rupees a month tells her early when usage grows.

Practice (0/3 done)

Task 1 · Code · Javascript

Fail fast at startup. Write missingEnv(env, required) that returns the names in required that are missing from env or set to an empty string (or only spaces), in the same order as required. In a real app you would pass process.env.

Task 2 · Code · Javascript

Estimate a monthly bill. Write estimateMonthlyCost(usage, prices). usage = { servers, hours, storageGb, egressGb }. prices = { serverPerHour, storagePerGb, egressPerGb, freeEgressGb }. compute = servers x hours x serverPerHour. storage = storageGb x storagePerGb. transfer = (egressGb minus freeEgressGb, but never below 0) x egressPerGb. Return { compute, storage, transfer, total }, each rounded to 2 decimal places with Math.round(x * 100) / 100. All prices are in rupees and made up for practice.

Task 3 · Practice

Write your own deploy checklist for a Node.js API going to production for the first time. It should be short enough to follow every time.

Quick quiz

Question 1

1.You give a platform your code and it handles servers, OS and HTTPS. Which model is this?

Question 2

2.Which DNS record points a name to another name, often used with hosting platforms?

Question 3

3.Why must Let's Encrypt certificate renewal be automatic?

Question 4

4.In a zero-downtime deploy, when do you stop the old version?

Question 5

5.What is the best first step to avoid a surprise cloud bill?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: Docker: packaging your app