Unit 4 Deployment
Unit 4 Deployment
You should not wait until the end of your project to think about how your application will be
deployed or run in a live environment. Instead, you need to consider the deployment
environment right from the beginning, because it can affect the way you design and build
your application.
🔍 Example Breakdown:
If your app will run on multiple servers (horizontal scaling),you can’t store user
sessions in memory, because each server won’t know what the other is storing.
You’ll need to store session data in a shared database or cache, like Redis.
If your users upload large files, and the deployment server has limited disk space,
you might need to use cloud storage (e.g., AWS S3) instead of saving files locally.
Encourages frequent and early releases to reduce waste and avoid unused builds.
Builds on Continuous Integration (CI):
o CI = Regularly integrating code.
o CD = Regularly delivering that code to production.
Mature teams:
o Push even the earliest "Hello World" versions to production.
o Automate the entire deployment pipeline.
o Can spin up new environments quickly and reliably.
Always list what your app needs to run (like libraries, packages).
Don't assume the system has what you need.
Keep dependencies bundled with the app, so setup is easy and repeatable.
Databases, caches, and other services are “add-ons” that can be plugged in/out.
Your app shouldn’t care where the service runs — just that it’s available.
Makes switching services (like moving from local DB to cloud DB) simple.
Don’t store things (like session info or files) in app memory or local disk.
Use shared services (like Redis or cloud storage) to save data.
Stateless apps are easier to scale and move.
Developer Machines
The way developers set up their local development environments matters a lot for efficiency,
consistency, and smooth deployment.
Developers should not have to struggle for hours just to run the code on their machine.
Tools like Vagrant and Docker allow for fast, automated, and identical setups for everyone
on the team.
Production Environments :
You can't use development tools like Vagrant directly in production. But the
deployment process should still be automated, consistent, and repeatable, using code-
based configuration.
Reuse what you can from local environments in production (e.g., build scripts,
container images).
Use tools like:
o Docker (to package your app the same way for local & prod)
o Infrastructure-as-Code tools (e.g., Terraform, AWS CloudFormation) to
automate environment setup.
Best Practices:
1. Multiple Environments:
o Local → QA → UAT → Staging → Production
o All treated like “mini-productions”—no special cases.
2. Use Configuration Files:
o Different instance sizes or URLs? No problem.
o Use parameterized templates to express differences.
o Example: use the same code, just swap the config.
3. Version Everything:
o Infrastructure code (like your app code) should be:
Stored in Git
Versioned
Deployed together with app changes
Traditional Way:
Ops team gives you a server.
You SSH into it, clone the code from Git, run npm install, etc.
This approach is error-prone:
o Dependency mismatches (e.g., different Node.js versions)
o Outages from external services (e.g., NPM down)
o Manual steps = more mistakes
DevOps Way:
Build, deploy, and run are separated (a 12-factor app principle).
You should build your app once, then deploy the same ready-to-run package
everywhere (like QA, staging, production).
This makes your app behave like any other system-installed software.
Bundled inside your package Managed via package manager (apt, yum)
The build process happens before deployment, often in CI/CD pipelines (e.g., Jenkins,
GitHub Actions). The final package or container is pushed to a repository, ready to be
deployed anywhere.
1. Standardize Environments
Differences between prod, QA, and test environments should be:
🔽 Minimized
✅ Managed consistently
Examples:
You can start with basic shell scripts, but there are more powerful configuration
management tools, like:
Tool Description
4. Infrastructure Configuration
🔥 Firewall rules
👤 SSH users and permissions
📊 Monitoring tools (like Prometheus or Datadog agents)
� Log forwarding agents (e.g., sending logs to a centralized system)
5. Benefits of Automation
✅ Best Practice:
🛡️ This adds a security layer while still giving access for troubleshooting.
Tools like Ansible, Puppet, and Chef help define and maintain the desired state of
your systems.
Environment variables, .ini, or JSON files are common ways to inject configuration
without hardcoding values.
4. Automation is Critical:
Secure your environment with SSH bastions (jump boxes) instead of exposing
every server to the internet.
Developers SSH into the bastion and then access internal servers securely.
6. Types of Infrastructure:
7. PaaS vs IaaS:
Feature PaaS (Platform-as-a-Service) IaaS (Infrastructure-as-a-Service)
PaaS is easier to start with but has limitations (OS, storage, runtime).
IaaS gives more control but requires managing complexity.
8. Private Cloud:
9. Parameterization:
Use templates with dynamic values (e.g., instance size, AMI ID).
Helps reuse definitions across environments with minor tweaks.
Local setup can be lightweight and fast but might not mimic production exactly
(e.g., no CDN or LB).
Tools like Docker help simulate infrastructure to reduce surprises at deployment.
Relying on cloud-native tools boosts productivity but can lead to vendor lock-in.
Aim for portability and standardized interfaces to stay flexible.
Immutable Infrastructure
Definition:
Immutable infrastructure means once your app is deployed, the infrastructure and code
do not change. If updates are needed, you replace the old components with new versions
instead of modifying them in place.
Why Use Immutable Infrastructure?
Prevents “fragile” setups caused by undocumented or incremental changes.
Ensures all changes are intentional and reproducible.
Supports consistent environments across dev, test, and prod using the same
code/configuration.