Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!