Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda