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 →
- 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"]
- Or use Testcontainers inside the test code, which starts containers per test suite and works the same locally.
- Run migrations at the start of the job so the schema matches the code.
- 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.
More on Pipelines at scale
The CI pipeline takes 45 minutes. Developers want it under 10. How do you approach it?IntermediateYou have a monorepo with 40 services. Every commit builds and tests all of them. How do you fix that?AdvancedFlaky tests fail 1 in 5 runs and developers just click "re-run". How do you fix this culture and the tests?BeginnerYour self-hosted GitHub runners can't keep up at peak and sit idle at night. How do you run them at scale?AdvancedDocker builds in CI take 12 minutes because every runner starts with an empty cache. How do you speed them up?IntermediateHow do you secure the software supply chain from commit to production?Advanced