Customer App Data

Learn how customer app data helps you build scalable customer engagement applications on the Elarian Framework.

Customer app data allows you to store information specific to an application that would help your application make decisions at a later time. This data construct is different from metadata in that it is scoped to a particular appId; customer metadata can be accessed across applications.

Get customer app data

...

const resp = await customer.leaseAppData();

console.log(resp);

Customer app data is also sent to your application every time you receive an event notification

client.on('ussdSession', (notification, customer, appData, callback) => {
  console.log(appData);
});

Update customer app data

const customer = new client.Customer({ ... });

const resp = await customer.updateAppData({
  lastSeen: 1615465218971 // timestamp
});

console.log(resp);

You can also update customer app data by passing it to an event notification callback

client.on('ussdSession', (notification, customer, appData, callback) => {
  console.log(appData);

  const menu = { ... };

  const newAppData = {
    lastSeen: Date.now(),
  };

  callback(menu, newAppData);
});

Delete customer app data

...

const resp = await customer.deleteAppData();

console.log(resp);

You can also delete customer app data by passing an empty object to the event notification callback

client.on('ussdSession', (notification, customer, appData, callback) => {
  console.log(appData);

  const menu = { ... };

  callback(menu, null);
});

Synchronized data updates

Elarian implements a locking mechanism that helps guarantee synchronized data updates in scenarios where your application is distributed. Every time your application gets a customers app data, the data object is locked for a duration of 90s. In this window, every other attempt to fetch that customers app data will wait for the lock to be released.

The data lock is scoped to an individual customer, this means there's no wait overhead to the rest of your customers.