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

160
Visualizações
How to sync data between users ReactJS

I want to know if there is a way to have data be linked between different users. In my case I'm building a gift wish list and each item has a buy button attached to it. if the buy button is clicked and someone buys the item then the item no longer needs to be displayed. but i have no idea how sync that data between users. I tried using sqlite but I wasn't able to find a way to store the data that is returned from db.each since its asynchronous. I also thought of JSON but there didn't seem to be a good way to write to an external JSON file. I know that I can't be the only one with this issue but I don't really know what to search in order to find the answers I'm looking for.

TIA

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Three approaches I would suggest. (The problem isn't really tied to ReactJS)

1. Reactive Approach

  • Let the buy button buy and update the record accordingly in the backend denoting that it is sold.
  • Any succeeding requests for that backend will result in an error.
  • Up to you how you will do the UX, but usually a pop up saying the item is now sold out is enough. (This is when you can remove the said item from the view.)
  • This is far the easiest to implement in my opinion.
  • This is a classic solution to a race problem.

2. Real Time Approach

  • there are many solutions you can use to do this. I won't deep dive on what solutions you can use. But basically, you need to find a way to have an open connection between your data source and frontend enabling real time subscription (like Facebook notifications or messaging)
  • One solution is to use sockets as one of the comment dictates. Basically, when a request to the backend was made, there should be an event that would trigger a push to all subscribed frontends that this item was bought. (You can then do the necessary frontend UX after receiving such event.)
  • You will still need to do the reactive solution just in case.
  • This is hard to implement since your number one problem is to support scale and possibly an event driven architecture.

3. Near Real Time Approach

  • Not really elegant, but you can just poll for changes in the backend in the background and when something was updated you can do the necessary UX.
  • Still need to do the reactive solution.
  • Be careful though on the interval though, it might mimic a DDoS attack but nothing a cache can't solve if it's just pure GET requests.
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