Bird
Raised Fist0
Microservicessystem_design~10 mins

Docker basics review in Microservices - Scalability & System Analysis

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Scalability Analysis - Docker basics review
Growth Table: Docker Basics Review
Users/ContainersWhat Changes?
100 users / 10 containersSingle host runs containers smoothly. Docker daemon handles container lifecycle. Network and storage simple.
10,000 users / 100 containersHost CPU and memory usage rises. Need container orchestration (e.g., Docker Compose or Kubernetes).
1,000,000 users / 1,000+ containersSingle host insufficient. Must use cluster of hosts. Orchestration critical for scheduling, scaling, health checks. Shared storage and network overlay needed.
100,000,000 users / 10,000+ containersMassive cluster with multi-region deployment. Advanced orchestration with auto-scaling, service mesh, and monitoring. Network bandwidth and storage become bottlenecks.
First Bottleneck

At small scale, the Docker host's CPU and memory limits break first because each container uses resources. As users and containers grow, the single host cannot handle all containers, causing slowdowns and failures.

Scaling Solutions
  • Horizontal scaling: Add more hosts to run containers in parallel.
  • Container orchestration: Use Kubernetes or Docker Swarm to manage container deployment, scaling, and health.
  • Caching: Use caching layers outside containers to reduce load.
  • Storage: Use shared or distributed storage solutions to handle container data.
  • Networking: Use overlay networks and service meshes to manage container communication efficiently.
Back-of-Envelope Cost Analysis
  • Each host can run ~50-100 containers depending on resources.
  • At 1,000 containers, need ~10-20 hosts.
  • Network bandwidth per host: 1 Gbps (~125 MB/s) limits container communication.
  • Storage IOPS must scale with container data needs; shared storage adds cost.
  • Orchestration adds overhead but reduces manual management cost.
Interview Tip

Start by explaining Docker basics and resource limits on a single host. Then discuss how scaling users and containers requires orchestration and multiple hosts. Mention bottlenecks and how to solve them step-by-step.

Self Check

Your Docker host runs 100 containers and handles 1000 requests per second. Traffic grows 10x. What do you do first?

Answer: Add more hosts and use container orchestration to distribute containers and load. This prevents resource exhaustion on a single host.

Key Result
Docker on a single host works well for small scale, but as users and containers grow, resource limits cause bottlenecks. The first fix is horizontal scaling with orchestration to manage containers across multiple hosts.

Practice

(1/5)
1. What is the main purpose of Docker in microservices architecture?
easy
A. To replace the need for servers entirely
B. To write application code faster
C. To package applications with all dependencies for consistent deployment
D. To monitor network traffic between services

Solution

  1. Step 1: Understand Docker's role

    Docker packages applications with their dependencies to ensure they run the same everywhere.
  2. Step 2: Compare options

    Only To package applications with all dependencies for consistent deployment describes packaging apps with dependencies; others describe unrelated tasks.
  3. Final Answer:

    To package applications with all dependencies for consistent deployment -> Option C
  4. Quick Check:

    Docker packages apps = B [OK]
Hint: Docker bundles apps and dependencies for consistent runs [OK]
Common Mistakes:
  • Thinking Docker replaces servers
  • Confusing Docker with coding tools
  • Assuming Docker monitors network
2. Which Docker command is used to create a new image from a Dockerfile?
easy
A. docker run
B. docker start
C. docker push
D. docker build

Solution

  1. Step 1: Identify command purpose

    docker build creates an image from a Dockerfile.
  2. Step 2: Eliminate other commands

    docker run starts containers, docker start restarts stopped containers, docker push uploads images to a registry.
  3. Final Answer:

    docker build -> Option D
  4. Quick Check:

    Build = create image [OK]
Hint: Build creates images; run starts containers [OK]
Common Mistakes:
  • Using docker run to create images
  • Confusing docker start with build
  • Thinking docker push creates images
3. Given this Docker command sequence, what happens?
docker build -t myapp .
docker run -d --name app1 myapp
medium
A. Builds an image named myapp and runs it detached as container app1
B. Runs a container named myapp and builds app1 image
C. Builds a container named myapp and runs it interactively
D. Fails because -d and --name cannot be used together

Solution

  1. Step 1: Analyze docker build command

    docker build -t myapp . creates an image tagged 'myapp' from current directory.
  2. Step 2: Analyze docker run command

    docker run -d --name app1 myapp runs container named 'app1' in detached mode from image 'myapp'.
  3. Final Answer:

    Builds an image named myapp and runs it detached as container app1 -> Option A
  4. Quick Check:

    Build image then run container detached = A [OK]
Hint: Build tags image; run starts container with name and mode [OK]
Common Mistakes:
  • Mixing image and container names
  • Thinking -d disables naming
  • Confusing build and run order
4. Identify the error in this Docker command:
docker run --name mycontainer -p 8080 myimage
medium
A. Port mapping syntax is incomplete
B. Missing container name
C. Image name is missing
D. Cannot use -p with --name

Solution

  1. Step 1: Check port mapping syntax

    -p 8080 is incomplete; it should specify host and container ports like -p 8080:80.
  2. Step 2: Verify other parts

    Container name and image name are present; no restriction on using -p with --name.
  3. Final Answer:

    Port mapping syntax is incomplete -> Option A
  4. Quick Check:

    Port mapping needs host:container format [OK]
Hint: Port mapping needs host:container format [OK]
Common Mistakes:
  • Omitting container port in -p
  • Assuming image name is missing
  • Thinking -p and --name conflict
5. You want to deploy multiple microservices using Docker containers on one host. Which approach best ensures isolation and easy management?
hard
A. Run all microservices inside a single container
B. Use separate containers for each microservice with individual Dockerfiles
C. Install all microservices directly on the host OS without containers
D. Use one container per microservice but share the same network and volumes without isolation

Solution

  1. Step 1: Understand container isolation

    Each microservice should run in its own container for isolation and independent management.
  2. Step 2: Evaluate options

    Use separate containers for each microservice with individual Dockerfiles uses separate containers with individual Dockerfiles, enabling isolation and scalability. Run all microservices inside a single container mixes services, reducing isolation. Install all microservices directly on the host OS without containers lacks container benefits. Use one container per microservice but share the same network and volumes without isolation shares resources without isolation.
  3. Final Answer:

    Use separate containers for each microservice with individual Dockerfiles -> Option B
  4. Quick Check:

    Separate containers = isolation + management [OK]
Hint: One container per microservice for isolation and scaling [OK]
Common Mistakes:
  • Running all services in one container
  • Skipping containers and installing on host
  • Sharing networks and volumes without isolation