Integration tests need a real Postgres and Redis in CI. How do you provide them?

BeginnerScenarioPipelines at scale
Answer

Situation read → Tests against a shared database are slow and flaky. Each CI job should get its own throwaway instances.

What I'd do →

  1. Use service containers in GitHub Actions (or services: in GitLab CI):
services:
  postgres:
    image: postgres:17
    env:
      POSTGRES_PASSWORD: test
    ports: ["5432:5432"]
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 5s --health-retries 10
  redis:
    image: redis:7
    ports: ["6379:6379"]
  1. Or use Testcontainers inside the test code, which starts containers per test suite and works the same locally.
  2. Run migrations at the start of the job so the schema matches the code.
  3. Use the same major versions as production.

Why → Isolated, disposable dependencies make tests repeatable and parallel-safe.

Interview tip → Mention health checks on service containers; without them tests start before the DB is ready.

All Real-World Interview questions Roadmap: Interview readiness

More on Pipelines at scale