简体   繁体   中英

NodeJs best practices for scheduled process?

I'm currently working on a large scale Tiktok like app where a video will be exist for 5 days. My question how should I schedule to take down the video after 5 days? 2 Method that I came up are either I can build a background service worker that will continuously loop through the database and check if the video should be down or not OR I can put it in a setTimeOut() for 5 days, which means its gonna be on the RAM and there need to be a service that restart all the setTimeOut() in case the server is down. I'm using AWS EC2 so I wonder which method will be scalable and save some money. Thank you.

you could use queue management for storing tasks on it.

suppose you have a queue that holds your tasks inside it. you have a consumer that listens to your queue. if a message sends, the consumer reads the message and handles the job for you.

but there is a challenge. when you should send your task into the queue and when the consumer should handle the task. for the availability part, message brokers are the good choices but managing the process is up to your approach, if you have a microservice system design, you can write your consumer as a service.

rabbit-MQ and kafka are the most popular message brokers.

of course, you should know about task queue and message queues concepts.

take a look at the difference:

https://serverfault.com/questions/669434/whats-the-difference-between-a-task-queue-and-a-message-queue-in-rabbitmq

https://www.tech101.in/message-queue-and-task-queue/

there is a simple task queue package that works with Redis :

bee-queue

note that, handling the message brokers are complicated in the production level.

and you should know about cron systems too:

https://en.wikipedia.org/wiki/Cron

https://www.redhat.com/sysadmin/automate-linux-tasks-cron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM