Real-time data subscription

When on app A a product price is changed, app B should update the displayed price there, too, ideally as soon as possible. I would let the updated field flash briefly and show a temporary message that the value just has changed to notify the user.

websockets come to mind as a faster and more efficient alternative to classical polling.
For keeping everything simple I want to use something very high-level.

What libraries would you recommend?

It depends on your back-end. I use socket.io for nodejs and signalr for dot.net.

i’ve made the backed in java (spring), in my typescrit code (ionic with angular) i call a refresh function every X seconds, depending on the type of data i’m handling:

if i’m on a product page, i call the refresh method on “add to cart”, on “page enter” and every 30-60 secs if the user stays on the page.

For “less important data” i just call a refresher inside a setInterval, every 2-3 minutes

You are using REST HTTP API for the apps to communicate with the server?

Are you using an API generator or something else to bind the API to the app/react?

i’m using REST API, without any api generator

i just use import { HttpClient } from ‘@angular/common/http’;

and an example of function to get the items:

  doPostApplicationJsonBearer = (url: string, params: any, token: string) => {

    const headers = {
      "Accept": 'application/json',
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + token
    };
    return this.http.post<any>(url, params, { headers });
  };

  doGetApplicationJsonBearer = (url: string, token: string) => {
    const headers = {
      'Accept': 'application/json',
      'Content-Type': "application/json",
      'Authorization': 'Bearer ' + token
    };

    return this.http.get<any>(url, { headers });

  };

i’ve made a service provider, i call the functions from the components of my app, like this for example:

    getLastOrders() {
    this.http.doGetApplicationJsonBearer(this.myEndpoints.getLastOrders, this.tokenValue).subscribe(res => {
        this.lastOrders = res;
        console.log(res);
    }

my data are stored on google cloud, a mysql database