Simplify Your Application with Voximplant Key-Value Storage

Simplify Your Application with Voximplant Key-Value Storage

Like other serverless environments, the code you write for VoxEngine executes in isolation. This provides security and scalability, but sometimes your application needs to share data across instances. While our Net module enables your VoxEngine code to communicate with a backend or external service, that approach introduces multiple integration points.

To simplify development, Voximplant offers a key-value storage service as a standard feature in its serverless CPaaS platform. Our key-value storage enables you to share data across all of your communications applications and with your back-end systems, all from within VoxEngine. It eliminates the hassles of provisioning an external database and supports a range of important uses including stimulating environment variables, sharing user status information, non-atomic  counters and timers, or ephemeral credential storage. 

In this blog we’ll describe the key-value storage function and popular use cases. We’ll tell you how to access the storage function with your VoxEngine code. 

Data Storage Challenges

Regardless of whether you’re working with a traditional or serverless CPaaS platform, developers need data storage services for all but the simplest of applications. This is because application instances need to share information about the status of a communications session. 

In addition, back-end systems frequently need credentials to facilitate integrations. Examples include sharing VoIP and video usage data with billing systems, and sharing contact center agent data with a CRM for screen pop.

In these cases, developers typically have had to provision their own NoSQL databases like Redis to store data. While this may not be a huge impediment to developing an application, it does present friction that most developers prefer not to deal with. It can often be  a distraction that slows development and introduces additional operating costs. In addition, the database needs to scale with growth in application usage. 

Voximplant Offers Key-Value Storage

Key-Value Storage is operated by the VoxEngine ApplicationStorage module. It enables you to save key-value pairs that are unique for each application in your Voximplant account. Key-value pairs are persistent. Data produced by one scenario instance may be shared and modified by other instances of the same scenario or other scenarios under the same application.

Voximplant Key-Value Storage is designed for in-memory storage use cases, similar to Redis or cloud services like AWS Elasticache. It is not intended for large amounts of data, file storage, or to be used as a persistent database.

How do You Access Key-Value Storage?

Key-value pairs may be accessed within the VoxEngine JavaScript API’s. After you’ve created a VoxEngine application, you must load the ApplicationStorage module. Then, you can use the put method to create a new variable as a key:value or update the value of an existing key. get will retrieve a key’s value and delete will destroy the key. 

Time to Live and Maximum duration

ApplicationStorage.put also includes a ttl option that sets a time to live (TTL) in seconds. When this is used, the key will be deleted after the specified TTL value. The TTL is converted to an expireAt Unix timestamp field as part of the storage object.  If not provided as part of ApplicationStorage.put, the TTL value defaults to 30 days ( 7776000 seconds). Application Storage objects have a maximum TTL of 90 days. Values larger than 90 days (7776000 seconds) are automatically rounded down to 90 days (7776000 seconds).

Application Storage Example

The following example shows how to retrieve all storage data from ApplicationStorage and then increment a counter.

require(Modules.ApplicationStorage);
 
// Return all Application Storage Data
// [{"key":"foo","value":"7","expireAt":"1601653048"}, {"key":"bar","value":"2","expireAt":"1604153847"}]
async function getStorage() {
   try {
       let kvs = await ApplicationStorage.keys();
       return await Promise.all(kvs.keys.map(async key => await ApplicationStorage.get(key)));
   }
   catch (err) {
       Logger.write(`Failure while reading ApplicationStorage: ${err}`);
   }
}
 
// Increment a counter
async function kvsCounter(counter) {
   try {
       let c = await ApplicationStorage.get(counter);
       if (c===null)
           c = 0;
       await ApplicationStorage.put(counter, (c.value | 0) + 1, 60 * 30); //expire after 30 min
   } catch (err) {
       Logger.write(`Failure while updating ApplicationStorage: ${err}`);
   }
}
 
getStorage()
   .then(data => Logger.write(`all ApplicationStorage data: ${JSON.stringify(data)}`))
   .then(() => kvsCounter('foo'))
   .then(() => VoxEngine.terminate())
   .catch(err => Logger.write(err));

See our Key-Value Storage tutorial for a full step-by-step guide and our Application Storage documentation for API details.

Key-Value Storage Benefits

Key-value storage benefits appeal to developers and operations personnel because this Voximplant feature can eliminate the need to provision a separate database.

Improve performance - local data accelerates read, modify and write operations
Reduce costs - eliminate external database, server and associated operating costs
Streamline operations - eliminate database capacity planning and management hassles
Strengthen security - data doesn’t leave the Voximplant cloud

Pricing

Key-Value Storage is an optional feature on the Voximplant platform. Usage fees are incurred on a per request basis, where Read and Write operations are separate transactions. In addition, Write fees vary based on the expireAt values that are set during the Write operation. The Time to Live values specified with ApplicationStorage.put are rounded up to 30, 60, or a maximum 90-day value for billing purposes.

Operation TTL Value Price per 100 requests
Read Any $0.0001
Write Up to 30 days $0.0001
Write 30 to 60 days $0.0002
Write 60 days to a maximum of 90 days $0.0003

For example, the fee for each Write operation with a 55-day TTL value is rounded up to 60-days which is priced at $0.0002 USD for 100 requests. A Read operation is priced at $0.0001. An application that places 5000 55-day TTL writes and 10,000 reads of this storage object a month would pay:

Write 5,000/100*0.0002  = $0.01
Read 10,000/100*0.0001= $0.01
TOTAL   $0.02

See our pricing page for more details.

Voximplant Key-Value Storage Reduces Application Friction

The Voximplant's Application Storage makes life for busy developers and operations teams a little easier. It eliminates the hassles of provisioning a separate external database to handle the need for a persistent data store. It puts this function inside the Voximplant cloud, alongside your application, where it benefits from the increased speed and security of a colocated data store service. 

Key-value storage is just one of many features in the VoxEngine serverless platform that helps developers accelerate time to market for communications applications. Stay tuned for more features coming soon, like the ability to access storage from our HTTP control API libraries.

Tags:key value storage
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.
Comments(0)
Add your comment

Please complete this field.

Recommended
Sign Up for a free Voximplant developer account or talk to our experts