Feature

Hive

Marketplace Product

Hive is an uberfast data storage system that uses key-value pairs to organize stored data. Datasets are stored in-memory, thereby all requests are processed at very low latencies. Hive is capable of processing a large number of requests rapidly and reliably. This technology opens new possibilities to a wide range of applications.

While the key-value storage is simple in principle, it offers an elegant and high-performing solution for a variety of use cases. These may include, but not limited to usage analytics, job queues, leaderboards, game management, real-time analytics and much more.

Backendless leverages the open source Redis in-memory data structure store to implement the functionality in Hive. You can learn more about Redis here.

Hive is currently available for UI Builder, Codeless (client-side and server-side), the JS SDK, and the iOS SDK. We’re working to add Hive support in the Android, Flutter, and .NET SDKs in early 2023. Click to view the REST docs, JavaScript docs, and iOS docs, all of which include Codeless examples.

Below are a few examples describing various usages for Hive:

Real-time Analytics
Modern applications require quick data processing to make decisions, and traditional databases may not provide sufficient performance. Hive’s very small latency allows streaming data to applications built for user analysis, ad-targeting, personalization, precise weather forecasts and other areas where speed matters.

Machine Learning
Whether the goal is to develop a fraud prevention system for the financial industry, deploy a virtual personal assistant, or create an application with real-time traffic alerts, Hive’s data storage ecosystem provides all required data types to do so.

Gaming Leaderboards
When thousands of users play an online game, it is necessary to save and update data quickly, especially if players perform in-game transactions or compete for a higher score. Hive’s Sorted Set data structure allows you to store a collection of unique score-value pairs, that can be used to link players to their current numerical state that can be a place in the leaderboard, the amount of earned in-game currency or even a trust score.

Hive Structure

Below is a summary of main data points identifying the structure of Hive in your Backendless application:

  • Your application may have multiple hives.
  • Each hive has a logical name that identifies it among other hives.
  • Every hive is a higher-level container that consists of 5 different data storage buckets.
  • Each bucket can store data of a specific data type.
  • These data types are List, Map, Key-Value, Set and Sorted Set.
  • Every bucket can store multiple key-value pairs, where the value must have the structure as defined by the bucket data type.

For instance, the table below highlights how these key-value pairs are structured within the system:

Data Type Key Value
key-value “Japan” “Tokyo”
list “names” “Mike”, “Bobby”, “Frank”, “Andrew”, “Simon”
map “fruits” “Apples”:0.99, “Oranges”:1.19
set “cars” “Sedan”, “Crossover”, “Coupe”, “SUV”
sorted-set “leaderboard” [[48,“Bob”], [32,“John”], [10,“Simon”], [3,“Jessica”]]

Data Types

The Hive system supports five core data types: List, Map, Key-Value, Set, and Sorted Set.

There are APIs for every data type to interact with the data stored in the corresponding bucket type. APIs provide functions that allow adding, modifying, deleting, moving, calculating, and performing other actions over data objects.

A single value in any data structure supported by Hive can be of any JSON data type. This includes strings, integers, booleans, dates, objects and arrays.

List

List is an unordered collection of values, and it means that values are stored in the list in the same order as they were added. Duplicate values are allowed (for a data structure that does not allow duplicates, see Set and Sorted Set).

Hive list data type with duplicate values

Every element in the List is located at a specific index position. Some API methods require index positions of values to modify or delete them, and some methods use index positions to add new items into a data structure. List indexes are 0-based, meaning the very first element in a List has the index of 0.

For example, the value A is located at the index position 0, and the value B is at the index position 1.

Hive index value example

Key-Value

The Key-Value data structure stores a single value for a key, where the keys must be unique. Keys must be strings, while values can be of any valid JSON data type. To retrieve a value for a key, use the key name in the API call.

Hive key-value data type example

Map

Map is a data structure where the value for a single key is an unordered collection of key-value pairs. The keys in the collection must be unique. The values can be of any data type and mapped one-to-one for each key.

Hive map data type example

Set

Set is a data structure where the value for a single key is a collection of unique values. Duplicates cannot be added to a Hive bucket of this data type.

Hive set data type example

Sorted Set

Sorted Set is a data structure where a single key’s value is a collection of unique score-value pairs. The score determines the order of items in the collection from the smallest to the largest. Values cannot contain duplicates, but at the same time the score can be the same across multiple values. If a few sorted-set items have an identical score, then these items are ordered lexicographically.

As you can see in the example below, values are ordered by score ranging from 1.0 to 3.0.

Hive sorted set data type example

If we insert a new item Sam with the score 1.5, the Sorted Set automatically reorders all elements within this data structure, placing Sam between Bob and Joe.

Hive sorted set data type with new data added

The order of elements in the sorted-set is called rank. The rank is the position of an element in the sorted-set which always starts from 0, meaning the very first element in a Sorted Set has the rank of 0. The rank of an element always depends on the current score. If the score changes, the value gets reordered in the sorted-set, and the corresponding rank also changes. In the example below you can see the rank of the elements in Sorted Set:

Hive sorted set data type with rank