Skip to Content
Lesson 1

Deployment Fundamentals & CI/CD

Workplace Context

Your team has successfully built and tested a new feature for your MERN application on their local machines. Now, it’s time to release it to users. As a developer on the team, you’re responsible for understanding the deployment process. Your tech lead has asked you to help document the steps required to move the application from a developer’s laptop to a live, production server. This involves explaining not just the “how,” but the “why” behind modern deployment practices like CI/CD, which are critical for releasing reliable software quickly.


Lesson Objectives

  • Differentiate between a development and a production environment.
  • Define Continuous Integration (CI) and Continuous Deployment (CD) and explain their benefits.
  • Outline the key stages of an automated CI/CD pipeline.
  • Describe the end-to-end workflow of deploying a web application from a Git commit to a live server.

From localhost to the World

Deployment is the process of taking your finished application code and making it available to end-users on a live server. While running an application with npm run dev is great for development, a production environment has a different set of requirements and challenges.

Production vs. Development Environments

AspectDevelopment Environment (localhost)Production Environment (Live Server)
GoalRapid iteration, debugging, and feature development.Stability, performance, and security for real users.
PerformanceNot a primary concern; tools like hot-reloading prioritize speed of change.Critical; code is minified, bundled, and optimized for fast loading.
SecurityLower priority; developer machines are generally trusted.Highest priority; servers are exposed to the internet and attacks.
DataUses mock data or a small, local database.Connects to a robust, secure, and backed-up production database.
Error HandlingDetailed error messages and stack traces are shown to aid debugging.Generic, user-friendly error messages are shown; detailed logs are kept private.
ServerA lightweight development server (e.g., webpack-dev-server).A robust, scalable web server (e.g., Nginx, Apache) or PaaS.

Introduction to CI/CD

In the early days of web development, deploying an application was a manual, error-prone process. A developer would have to FTP files to a server, manually run build commands, and hope nothing went wrong. Modern development relies on CI/CD to automate this process.

CI/CD is a methodology that allows development teams to deliver code changes more frequently and reliably. It’s a pipeline that automates the build, testing, and deployment of your application.

Continuous Integration (CI)

Continuous Integration is the practice of automating the integration of code changes from multiple contributors into a single software project.

The core idea is to merge code changes back to the main branch as often as possible. When a developer commits code to a shared repository (like GitHub), a CI service automatically builds the application and runs a suite of automated tests (e.g., unit tests, integration tests) against it.

  • Goal: To detect integration bugs early and ensure the main branch is always stable.
  • Trigger: A git push to the repository.
  • Outcome: A report indicating whether the build and tests succeeded or failed.

Continuous Deployment (CD)

Continuous Deployment is the practice of automatically deploying every change that passes the CI stage to the production environment.

If the build from the CI stage is successful, the CD part of the pipeline takes over and deploys the application to your live servers. This allows for a much shorter cycle between having an idea and releasing it to users.

  • Goal: To automate the release process and deliver value to users faster.
  • Trigger: A successful CI build on a specific branch (e.g., main).
  • Outcome: The new version of your application is live.

The CI/CD Deployment Workflow

Here is a step-by-step breakdown of a typical deployment workflow for a MERN application using a CI/CD pipeline:

  1. Commit to Git: A developer makes a change and pushes it to a feature branch in a GitHub repository. They then open a pull request to merge it into the main branch.
  2. Trigger CI: The pull request automatically triggers the CI pipeline. A CI server (like GitHub Actions) spins up a temporary environment.
  3. Build & Test: The server checks out the code, installs all dependencies (npm install for both client and server), builds the React app for production (npm run build), and runs the entire automated test suite.
  4. Merge: If all tests pass, the team reviews the code and merges the pull request into the main branch.
  5. Trigger CD: The merge to main automatically triggers the CD pipeline.
  6. Deploy: The CD server takes the production-ready build artifacts and deploys them to the hosting provider (e.g., Render). This might involve:
    • Deploying the backend code to a “Web Service.”
    • Deploying the built React assets to a “Static Site.”
    • Updating environment variables if necessary.
  7. Live!: The new version of the application is now live and available to users. If any step fails, the pipeline halts and notifies the team, preventing a broken release.

The specific steps and tools used in a CI/CD pipeline can vary widely depending on the hosting provider and the team’s preferences, so we can’t cover all the details here. However, the general workflow is the same.


Activities

Activity 1: Discussion

Task: As a class, discuss the following question:

“What are the biggest risks of deploying a complex application manually, without a CI/CD pipeline?”

Discussion Points:

  • Human error (forgetting a step)
  • Inconsistent environments (“it works on my machine”)
  • Slow release cycles
  • Difficulty in rolling back a bad deploy
  • Lack of automated quality checks

Summary

In this lesson, we explored the fundamental concepts of deploying a web application. You learned the critical differences between a development and a production environment and why specialized preparation is needed for a live release. We defined Continuous Integration (CI) as the practice of automatically building and testing code on every commit, and Continuous Deployment (CD) as the automatic release of successful builds to production. Finally, we outlined the complete CI/CD workflow, which forms the backbone of modern, agile software development.


Additional Resources