Cross row consistent data accessing
A method and a system include, for each predetermined time period in a plurality of predetermined time periods, writing a plurality of data rows comprising a set of data associated with a plurality of active entities, and updating an index table based on the plurality of data rows in the stats table, wherein the index table comprises an index row. The method further includes receiving from an electronic device via an interface a query corresponding to an entity, retrieving an index value from an index row included an index row, retrieving the current value from the stats table using the index value, generating a response to the query using the index value and the current value, and displaying the response on a display of the electronic device.
1 . A method comprising:
receiving, from a device, a query corresponding to an entity;
identifying, in a non-relational database, an index row from an index table, the index row including a plurality of index values representing stats values stored in a latest data row in a stats table, the plurality of index values being generated based on an index tree structure that comprises a plurality of root nodes, each root node comprising a version attribute that references one or more lower level nodes, the stats table including a plurality of stats values of a plurality of entities, each index value in the plurality of index values corresponding to a stats value of an entity in the latest data row;
generating a response to the query based on an index value and a stats value that correspond to the entity, the index row maintaining cross-row consistency during data updates in the stats table, the index row comprising index version data and a set of pointer maps for fetching current stats values from the stats table, such that a single atomic read of the index row provides a complete and consistent read of the current stats values stored in different rows of the stats table; and
causing display of the response on a user interface of the device.
2 . The method of claim 1 , further comprising:
identifying, based on the query, the stats table that includes data associated with the entity; and
retrieving, based on the index value, the stats value associated with the entity from the stats table, the stats value corresponding a value associated with the entity in the latest data row.
3 . The method of claim 2 , wherein the stats table is updated at a determined interval of time.
4 . The method of claim 2 , wherein each data row in the stats table comprises a plurality of counters that includes at least one of: a counter of a number of viewings, a counter of amount spent, or a counter of a number of interactions.
5 . The method of claim 2 , wherein a key-value store database comprises the stats table and the index row.
6 . The method of claim 1 , further comprising:
writing one or more data rows that include data associated with a plurality of entities at a determined interval of time; and
updating the index row based on the one or more data rows.
7 . The method of claim 6 , wherein the query is received during the writing of the one or more data rows that include the data associated with the plurality of entities.
8 . The method of claim 1 , wherein the index row comprises a data category, an entity type, and an index root identity.
9 . The method of claim 1 , wherein the query is received via an Application Program Interface (API).
10 . The method of claim 9 , further comprising:
transmitting, via the API, the response to the query to the device.
11 . A system comprising:
one or more processors; and
a memory storing instructions that, when executed by the one or more processors, configure the system to perform operations comprising:
receiving, from a device, a query corresponding to an entity;
identifying, in a non-relational database, an index row from an index table, the index row including a plurality of index values representing stats values stored in a latest data row in a stats table, the plurality of index values being generated based on an index tree structure that comprises a plurality of root nodes, each root node comprising a version attribute that references one or more lower level nodes, the stats table including a plurality of stats values of a plurality of entities, each index value in the plurality of index values corresponding to a stats value of an entity in the latest data row;
generating a response to the query based on an index value and a stats value that correspond to the entity, the index row maintaining cross-row consistency during data updates in the stats table, the index row comprising index version data and a set of pointer maps for fetching current stats values from the stats table, such that a single atomic read of the index row provides a complete and consistent read of the current stats values stored in different rows of the stats table; and
causing display of the response on a user interface of the device.
12 . The system of claim 11 , wherein the operations further comprise:
identifying, based on the query, the stats table that includes data associated with the entity; and
retrieving, based on the index value, the stats value associated with the entity from the stats table, the stats value corresponding a value associated with the entity in the latest data row.
13 . The system of claim 12 , wherein the stats table is updated at a determined interval of time.
14 . The system of claim 12 , wherein each data row in the stats table comprises a plurality of counters that includes at least one of: a counter of a number of viewings, a counter of amount spent, or a counter of a number of interactions.
15 . The system of claim 12 , wherein a key-value store database comprises the stats table and the index row.
16 . The system of claim 11 , wherein the operations further comprise:
writing one or more data rows that include data associated with a plurality of entities at a determined interval of time; and
updating the index row based on the one or more data rows.
17 . The system of claim 16 , wherein the query is received during the writing of the one or more data rows that include the data associated with the plurality of entities.
18 . The system of claim 11 , wherein the index row comprises a data category, an entity type, and an index root identity.
19 . The system of claim 11 , wherein the query is received via an Application Program Interface (API).
20 . A non-transitory computer-readable medium comprising instructions that, when executed by a hardware processor of a machine, cause the machine to perform operations comprising:
receiving, from a device, a query corresponding to an entity;
identifying, in a non-relational database, an index row from an index table, the index row including a plurality of index values representing stats values stored in a latest data row in a stats table, the plurality of index values being generated based on an index tree structure that comprises a plurality of root nodes, each root node comprising a version attribute that references one or more lower level nodes, the stats table including a plurality of stats values of a plurality of entities, each index value in the plurality of index values corresponding to a stats value of an entity in the latest data row;
generating a response to the query based on an index value and a stats value that correspond to the entity, the index row maintaining cross-row consistency during data updates in the stats table, the index row comprising index version data and a set of pointer maps for fetching current stats values from the stats table, such that a single atomic read of the index row provides a complete and consistent read of the current stats values stored in different rows of the stats table; and
causing display of the response on a user interface of the device.