Scenario-Based Questions And Answers

 

1️⃣ Your Dockerized Django app works locally but fails in production. How do you debug?

Scenario

App runs fine with Docker Compose locally but crashes on server.

Approach

  1. Check running containers

    docker ps -a
  2. Check logs

    docker logs <container_id>
  3. Check environment variables

  4. Verify database connectivity

  5. Check network configuration

  6. Inspect container

    docker inspect <container_id>

Most failures are due to:

  • Missing env variables

  • Database host mismatch

  • Static files not collected

  • DEBUG=False misconfiguration

2️⃣ Your Celery tasks are not executing. What will you check?

Stack Example

  • Django

  • Celery

  • Redis

Debug Steps

  1. Is Redis running?

    docker ps
  2. Check Celery worker logs

    docker logs celery_container
  3. Verify broker URL:

    CELERY_BROKER_URL = "redis://redis:6379/0"
  4. Ensure task is decorated:

    @shared_task
    def send_email():
    pass
  5. Confirm worker started:

    celery -A project worker -l info

3️⃣ Production server CPU is 100%. How do you handle it?

Investigation Steps

  1. SSH into server

  2. Check process usage:

    top
    htop
  3. Check container stats:

    docker stats

Possible Reasons

  • Infinite loop in code

  • Too many Gunicorn workers

  • Memory leak

  • High traffic spike

Fix

  • Adjust Gunicorn workers:

    workers = (2 × CPU cores) + 1
  • Add autoscaling

  • Use load balancer

  • Add caching (Redis)

4️⃣ Deployment failed after merging to main branch. What will you do?

Ideal CI/CD Setup

Using:

  • GitHub Actions

  • Jenkins

Debug Plan

  1. Check pipeline logs

  2. Identify failed stage

  3. Rollback to previous stable version

  4. Fix issue in feature branch

  5. Redeploy

Mention:

  • Blue-Green deployment

  • Zero downtime deployment

  • Rollback strategy

5️⃣ Database container crashed and data is lost. Why?

Root Cause

No volume configured.

Bad setup:

db:
image: postgres:15

Correct setup:

db:
image: postgres:15
volumes:
- postgres_data:/var/lib/postgresql/data

Lesson

Always use Docker volumes for persistent storage.


6️⃣ How would you scale a Django app handling 1M users?

Architecture

  • Nginx Load Balancer

  • Multiple Django containers

  • Managed DB (RDS)

  • Redis caching

  • Celery workers

  • CDN for static files

Cloud Options:

  • Amazon ECS

  • Kubernetes

Key Concepts to Mention

  • Horizontal scaling

  • Stateless containers

  • Caching strategy

  • Read replicas

  • Rate limiting

7️⃣ Docker image size is 1.5GB. How do you reduce it?

Steps

  • Use python:3.12-slim

  • Multi-stage builds

  • Remove build dependencies

  • Use .dockerignore

  • Use --no-cache-dir

Example:

RUN pip install --no-cache-dir -r requirements.txt

8️⃣ How do you secure secrets in production?

Never store in:

  • Git repository

  • Docker image

Use:

  • Environment variables

  • AWS Secrets Manager

  • Kubernetes secrets

Cloud example:

  • AWS Secrets Manager

9️⃣ Users report slow API responses. What will you check?

Debug Strategy

  1. Enable logging

  2. Check DB query performance

  3. Add Django debug toolbar locally

  4. Check slow queries

  5. Add indexing

  6. Add caching

Advanced Fixes

  • Redis caching

  • Query optimization

  • Use connection pooling

  • Add CDN

  • Add load balancer

🔟 How do you achieve zero-downtime deployment?

Methods

  • Blue-Green deployment

  • Rolling updates

  • Canary deployment

Using:

  • Kubernetes

  • Docker Swarm

Advanced Scenario (Senior-Level)

1️⃣1️⃣ Production database is slow after traffic increased 5x. What will you do?

Answer structure:

  1. Check slow query logs

  2. Add indexes

  3. Add read replicas

  4. Add caching

  5. Optimize ORM queries

  6. Consider sharding

1️⃣2️⃣ A container keeps restarting automatically. Why?

Check:

docker ps
docker inspect <id>

Possible causes:

  • Health check failure

  • Crash in entrypoint

  • Memory limit exceeded

  • Wrong command in CMD


Comments

Popular posts from this blog

Database Integration in FastAPI (SQLAlchemy CRUD)

Middleware & CORS in FastAPI

Python Data Handling