DEV Community

Naval Kishor Upadhyay
Naval Kishor Upadhyay

Posted on

12-Factor App Principle #2: Dependencies

Goal

Ensure your app clearly states and isolates everything it needs to run, so it behaves the same way everywhere — from a developer’s laptop to production servers.


What It Means

Dependencies are all the extra tools, libraries, or frameworks your app needs to function.

For example, if your app sends emails, it might depend on an email-sending library.

  • Declare dependencies – List them in a manifest file (e.g., package.json for Node.js, requirements.txt for Python) so anyone can install them easily.
  • Isolate dependencies – Keep them separate from the system’s own software to avoid conflicts — usually by using virtual environments or containers.
  • No hidden dependencies – Never rely on software being installed on the host machine without declaring it.

Why It Matters

  • Predictable results – The app works the same everywhere, reducing bugs and delays.
  • Faster onboarding – New team members can set up their environment quickly.
  • Easier scaling – When adding new servers, all needed software is installed automatically.
  • Risk reduction – Prevents “it works on my machine” situations.

Example

A Python data-processing app:

  1. Lists all required packages (pandas, numpy) in a requirements.txt file.
  2. Developers run pip install -r requirements.txt to set up everything.
  3. The app runs inside a Docker container, keeping dependencies separate from the host system.

Best Practices

  • Always use a manifest file to list dependencies.
  • Use a dependency manager (npm, pip, Maven) to install them.
  • Keep dependencies isolated in virtual environments or containers.
  • Update dependencies regularly, but test before deploying.
  • Avoid unnecessary dependencies to keep things simple and secure.

Takeaway

Declare everything your app needs and keep it isolated from the system.

This ensures consistent behavior, faster setup, and easier scaling — for both developers and operations teams.

Top comments (0)