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
-
Check running containers
docker ps -a -
Check logs
docker logs <container_id> -
Check environment variables
-
Verify database connectivity
-
Check network configuration
-
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
-
Is Redis running?
docker ps -
Check Celery worker logs
docker logs celery_container -
Verify broker URL:
CELERY_BROKER_URL = "redis://redis:6379/0" -
Ensure task is decorated:
@shared_task
def send_email():
pass -
Confirm worker started:
celery -A project worker -l info
3️⃣ Production server CPU is 100%. How do you handle it?
Investigation Steps
-
SSH into server
-
Check process usage:
top
htop -
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
-
Check pipeline logs
-
Identify failed stage
-
Rollback to previous stable version
-
Fix issue in feature branch
-
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
-
Enable logging
-
Check DB query performance
-
Add Django debug toolbar locally
-
Check slow queries
-
Add indexing
-
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:
-
Check slow query logs
-
Add indexes
-
Add read replicas
-
Add caching
-
Optimize ORM queries
-
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
Post a Comment