Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
How to ensure that a job is processed only once with Firebase

I am adding tasks as Docs in a Firestore collection. On the Backend, I have multiple NodeJs stateless instances that process these tasks. All the instances are listening to realtime change in the collection

firestore().collection('Tasks').onSnapshot(startTask, onError);

In this case all the NodeJs instances will be notified when a Task is added. How can I ensure that only one of them process the task? I though about using firebase-queue but it seems that the project is obsolete. Is there a way to do that without extra modules? Running the NodeJs as Firebase function is not an option for me.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

One possible solution would be to add a "treated" flag to the Firestore document through a Transaction.

A given Node.js instance should only process this Task if it is not flagged as treated (e.g. you check at the beginning of the transaction if the field treated is set to true and if it is the case you throw an error, see the examples). And after having successfully processed it the Node.js instance shall flag the doc as treated (within the same Transaction of course).

Since you use a Node.js server (i.e. you use the Node.js server client library) the transaction places a lock on the Task document it is reading and therefore the other instances cannot modify the document. This way you are sure it will be treated only once.

More details on data contention in the server client libraries here in the doc.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda