Bird
Raised Fist0
Expressframework~20 mins

Zero-downtime deployment concept in Express - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Zero-Downtime Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main goal of zero-downtime deployment in Express apps?
Choose the best description of zero-downtime deployment for an Express server.
ATo deploy new code only during scheduled maintenance windows with downtime.
BTo restart the server immediately after deployment, causing a brief downtime.
CTo update the server code without stopping the server or dropping user requests.
DTo disable all incoming requests during deployment to avoid errors.
Attempts:
2 left
💡 Hint
Think about user experience during deployment.
❓ component_behavior
intermediate
2:00remaining
How does a load balancer help achieve zero-downtime deployment?
Select the option that best explains the role of a load balancer in zero-downtime deployment.
AIt distributes incoming requests between old and new server instances to avoid downtime.
BIt restarts the server automatically after deployment.
CIt blocks all traffic during deployment to prevent errors.
DIt directs traffic only to the old server version until the new one is fully ready.
Attempts:
2 left
💡 Hint
Think about how traffic is managed between multiple servers.
❓ lifecycle
advanced
3:00remaining
What is the correct sequence for zero-downtime deployment steps in Express?
Order the steps to perform a zero-downtime deployment correctly.
A1,2,3,4
B2,1,3,4
C1,3,2,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Think about starting new first, then switching traffic, then stopping old.
🔧 Debug
advanced
2:30remaining
Why does this zero-downtime deployment code cause downtime?
Identify the problem in this Express deployment snippet: const server = app.listen(3000); // Deploy new code server.close(); app.listen(3000); Options:
AThe port 3000 is not freed immediately after server.close(), causing a bind error.
BCalling server.close() stops the server before the new one starts, causing downtime.
CThe new app.listen(3000) call is missing a callback, causing errors.
DThe app variable is not reinitialized with new code before listening.
Attempts:
2 left
💡 Hint
Think about when the server stops accepting requests.
❓ state_output
expert
2:00remaining
What is the output of this Express zero-downtime deployment simulation?
Given this simplified code simulating zero-downtime deployment, what is logged? let activeServers = 1; function deployNewVersion() { activeServers++; console.log(`Servers running: ${activeServers}`); activeServers--; console.log(`Servers running: ${activeServers}`); } deployNewVersion();
A
Servers running: 1
Servers running: 1
B
Servers running: 1
Servers running: 2
C
Servers running: 2
Servers running: 2
D
Servers running: 2
Servers running: 1
Attempts:
2 left
💡 Hint
Track the value of activeServers after each operation.

Practice

(1/5)
1. What is the main goal of zero-downtime deployment in an Express app?
easy
A. Keep the app running without interruption during updates
B. Stop the app completely before updating
C. Restart the server manually after every update
D. Disable all routes temporarily during deployment

Solution

  1. Step 1: Understand zero-downtime deployment purpose

    It aims to keep the app available and responsive while new code is deployed.
  2. Step 2: Compare options with this goal

    Only keeping the app running without interruption matches zero-downtime deployment.
  3. Final Answer:

    Keep the app running without interruption during updates -> Option A
  4. Quick Check:

    Zero-downtime = no interruption [OK]
Hint: Zero downtime means no app stops during update [OK]
Common Mistakes:
  • Thinking the app must stop to update
  • Confusing manual restart with automatic update
  • Assuming routes must be disabled during deployment
2. Which Node.js module helps run multiple instances of an Express app for zero-downtime deployment?
easy
A. http
B. path
C. fs
D. cluster

Solution

  1. Step 1: Identify module for multiple app instances

    The cluster module allows running multiple worker processes of the app.
  2. Step 2: Verify other modules' purposes

    http handles server requests, fs handles files, path handles file paths, none manage multiple processes.
  3. Final Answer:

    cluster -> Option D
  4. Quick Check:

    Multiple instances = cluster module [OK]
Hint: Cluster module manages multiple workers [OK]
Common Mistakes:
  • Choosing http for multiple processes
  • Confusing fs or path with process management
  • Not knowing cluster exists
3. Given this code snippet using cluster in Express, what happens when a worker crashes?
const cluster = require('cluster');
const express = require('express');
if (cluster.isMaster) {
  cluster.fork();
  cluster.on('exit', (worker) => {
    console.log('Worker died, starting a new one');
    cluster.fork();
  });
} else {
  const app = express();
  app.get('/', (req, res) => res.send('Hello'));
  app.listen(3000);
}
medium
A. A new worker starts automatically
B. No new worker starts, app crashes
C. The app stops completely
D. The master process crashes

Solution

  1. Step 1: Analyze cluster exit event handler

    When a worker exits, the master logs a message and forks a new worker.
  2. Step 2: Understand effect on app availability

    Replacing crashed workers keeps the app running without downtime.
  3. Final Answer:

    A new worker starts automatically -> Option A
  4. Quick Check:

    Worker crash triggers new worker fork [OK]
Hint: cluster.on('exit') forks new worker on crash [OK]
Common Mistakes:
  • Thinking app stops when worker dies
  • Assuming master process crashes
  • Missing automatic restart logic
4. Identify the error in this zero-downtime deployment code snippet:
const cluster = require('cluster');
const express = require('express');
if (cluster.isMaster) {
  cluster.fork();
  cluster.on('exit', () => {
    console.log('Worker died');
  });
} else {
  const app = express();
  app.listen(3000);
}
medium
A. Using cluster.isMaster instead of cluster.isWorker
B. Missing code to restart worker on exit
C. Express app should be created in master process
D. app.listen should be outside else block

Solution

  1. Step 1: Check cluster exit event handler

    The exit event logs a message but does not fork a new worker.
  2. Step 2: Understand impact on zero-downtime

    Without restarting workers, the app loses capacity and may cause downtime.
  3. Final Answer:

    Missing code to restart worker on exit -> Option B
  4. Quick Check:

    Exit handler must fork new worker [OK]
Hint: Restart workers on exit to avoid downtime [OK]
Common Mistakes:
  • Not restarting workers after exit
  • Confusing master and worker roles
  • Placing app.listen in wrong process
5. You want to deploy a new version of your Express app without downtime. Which approach best achieves this?
1. Use cluster to run multiple workers
2. On update, fork new workers with new code
3. Gracefully disconnect old workers after new ones are ready
4. Restart the entire server process immediately
Which steps should you follow?
hard
A. Steps 1 and 4 only
B. Only step 4
C. Steps 1, 2, and 3
D. Steps 2 and 4 only

Solution

  1. Step 1: Understand zero-downtime deployment best practices

    Running multiple workers (step 1) allows traffic to continue during updates.
  2. Step 2: Deploy new code by forking new workers (step 2) and gracefully disconnect old ones (step 3)

    This ensures no requests are dropped and old workers finish their tasks.
  3. Step 3: Avoid immediate server restart (step 4) as it causes downtime

    Restarting the whole server stops all workers at once, causing downtime.
  4. Final Answer:

    Steps 1, 2, and 3 -> Option C
  5. Quick Check:

    Fork new workers and gracefully disconnect old [OK]
Hint: Fork new workers before disconnecting old ones [OK]
Common Mistakes:
  • Restarting server immediately causing downtime
  • Not gracefully disconnecting old workers
  • Skipping multiple worker setup
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard