Skip to content

triggr/backend-node-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”€ Leader Election Challenge

🧠 Scenario

You're running multiple instances of a Node.js app. Only ONE instance should actively perform a recurring background task β€” polling a 3rd-party API every 5 seconds.

If the leader goes down, another instance must take over within 5 seconds. Redis will be used to coordinate this.

βœ… Your Task

  • Implement leader election using Redis.
  • Only the leader should perform the polling task.
  • Automatically fail over if the leader dies.
  • Implement /status endpoint to show:
    • Whether this instance is leader
    • When it last polled the API

πŸ§ͺ Simulating Multiple Instances

PORT=3000 npm start
PORT=3001 npm start

Watch the logs to see leadership change and polling activity.

πŸ“¦ Commands

npm install
npm start

πŸ“ Project Structure

  • src/index.js - App entrypoint
  • src/lib/leader.js - Leader election logic (you implement)
  • src/tasks/poll.js - Task runner logic (only leader runs it)
  • src/routes/status.js - Status endpoint

πŸ›  Assumptions

  • You can mock the 3rd-party API with console.log
  • Do not use a DB β€” everything should work with Redis and in-memory state
  • Use ioredis or redlock if you prefer (both supported)

Good luck!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published