SlideShare a Scribd company logo
1 of 28
Countdown to Zero
Counter Use Cases in Aerospike
2 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 I’m Ronen Botzer, and I’m a solutions architect at Aerospike.
 I’ve worked at Aerospike since June 2014, first on the Python and PHP clients.
 I’m active on StackOverflow and the Aerospike community forum.
 This is the third in a series of tech talks about data modeling.
 Check out the slides from the previous ASUG Israel meetups.
Welcome to Aerospike User Group Israel #3
3 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 A Quick Overview of Aerospike Data Model and Storage
 Counter Use Cases
 Data Capping – Telecom
 Frequency Capping – Ad Tech
 Consolidating Counters
 Mitigating Hot Counters
 Strong Consistency
 Counters
 Ticket Inventory – Countdown to Zero
 Summary
Agenda
4 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Aerospike is a Primary Key Database
Objects stored in Aerospike are called records
A bin holds the value of a supported data type: integer, double, string, bytes, list, map,
geospatial
Every record is uniquely identified by the 3-tuple (namespace, set, user-key)
A record contains one or more bins
(namespace, set, user-key)
EXP – Expiration Timestamp
LUT – Last Update Time
GEN – Generation
RECORD
EXP LUT GEN BIN1 BIN2
5 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 Aerospike is a row-oriented distributed database
 Rows (records) contain one or more columns (bins)
 Similar to an RDBMS with primary-key table lookups
 Single record transactions
 Namespaces can be configured for strong consistency
Aerospike Concepts
Aerospike RDBMS
Namespace Tablespace or Database
Set Table
Record Row
Bin Column
Bin type
Integer
Double
String
Bytes
List (Unordered, Ordered)
Map (Unordered,
K-Ordered, KV-Ordered)
GeoJSON
6 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 Integer
 8B of storage (64-bit)
 In places where signed values are needed (secondary indexes) the integer is
signed in the range of –(2^63) to (2^63) – 1.
 Double
 64-bit IEEE-754
 Both Integer and Double values can be used for counters.
 Support the atomic increment() operation.
 Can be stored in special data-in-index namespaces.
Numeric Data Types in Aerospike
7 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Namespace Storage
8 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Data Capping
namespace users {
memory-size 80G
replication-factor 2
prefer-uniform-balance true
partition-tree-sprigs 8192
storage-engine device {
write-block-size 128K
data-in-memory false
read-page-cache true
post-write-queue 1024
write-block-size 128K
device /dev/nvme1n1p1
device /dev/nvme1n1p2
device /dev/nvme1n1p3
device /dev/nvme2n1p1
device /dev/nvme2n1p2
device /dev/nvme2n1p3
}
}
9 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
('users', 'mobile', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2')
--
name: 'Jasper Madison Jr.'
age: 27
payment-method: [
{ 'type': 'visa', 'last4’: 6164,
'expires': '2019-09'},
{
'type': 'mastercard', 'last4': 7147,
'expires': '2023-03'}
]
number: [ 1, 408, 5551212 ]
data: 10711339520
 Atomically increment() the integer value of data to implement a counter
 What's the problem with this approach?
Data Capping
10 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 Think about the access patterns.
 The naive implementation has the user's data stored in a single record.
 Minimizes the amount of memory used by this namespace.
 Reduces the number of reads.
 Problem: the data counter updates frequently.
 Solution: split the data counter into a separate in-memory namespace.
 Consider using the data-in-index optimization.
Optimizing Counters – Namespace Considerations
11 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Optimizing Counters – Namespace Considerations
namespace counters {
memory-size 20G
default-ttl 1d
replication-factor 2
partition-tree-sprigs 8192
prefer-uniform-balance true
single-bin true
data-in-index true
storage-engine device {
data-in-memory true
filesize 40G
write-block-size 256K
file /opt/aerospike/data/counters.dat
}
}
12 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
('counters', 'mobdata', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|2019-02')
--
: 10711339520
• Initialize this record with an explicit 0 value each month
• On all writes (each increment) set the TTL to -1, i.e. NEVER_EXPIRE
• Combine the increment with a read. After every update the app knows the latest value
• Archive the counter after rolling to the new month
Data Capping – Counter Using Data in Index
13 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
from aerospike_helpers.operations import operations as oh
key = ('counters', mobdata', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|2019-02')
ops = [
oh.increment('', 1500),
oh.read('')
]
ttl = aerospike.TTL_NEVER_EXPIRE # AKA ttl -1
(key, meta, bins) = client.operate(key, ops, {'ttl': ttl},
{'timeout': 50})
Data Capping – Increment and Read in a single Transaction
14 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05')
--
: 3
 Keep track of ads served to a user in a given day.
 Compound key of userID | adID | day
 Increment should work as an upsert.
 Initial TTL of 24 hours (use the default TTL of 1 day).
 Do not update the TTL if the record exists, by setting it to -2.
Frequency Capping
15 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Frequency Capping
from aerospike import exception as e
key = ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05')
try:
(key, meta, bins) = client.get(key, {'timeout': 20})
if bins[''] < AD_LIMIT:
client.increment(key, '', 1, {'ttl': aerospike.TTL_DONT_UPDATE}) # aka ttl -2
# continue and attempt to serve the ad
except e.RecordNotFound:
ttl = aerospike.TTL_NAMESPACE_DEFAULT # AKA ttl 0, inherit the default-ttl
client.put(key, '', 1, {'ttl': ttl},
policy={'exists': aerospike.POLICY_EXISTS_CREATE})
16 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|cmp123|2019-03-05')
--
: {
'adx123': 2,
'adx456': 3
}
 Keep track of all campaign ads served to a user in a given day
 Compound key of userID | campaignID | day
 Map increment should work as an upsert, returning the current count
 Initial TTL of 24 hours (default TTL is 1 day)
 Do not update the TTL if the record exists, by setting it to -2.
 Only numeric data works with data-in-index. Use data-in-memory/single-bin.
Frequency Capping – Consolidating Counters
17 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Frequency Capping – Consolidating Counters
key = ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|cmp123|2019-03-05')
try:
val = client.map_get_by_key(key, 'ads', 'adx123', aerospike.MAP_RETURN_VALUE)
if val < AD_LIMIT:
# continue and attempt to serve the ad
client.map_increment(key, '', 'adx123', 1, {}, {'ttl': aerospike.TTL_DONT_UPDATE})
except e.RecordNotFound as err:
try:
ops = [
mh.map_put('', 'adx123', 1, {}),
mh.map_get_by_key('', 'adx123', aerospike.MAP_RETURN_VALUE)
]
ttl = aerospike.TTL_NAMESPACE_DEFAULT # AKA ttl 0, inherit the default-ttl
(key, meta, bins) = client.operate(key, ops, {'ttl': ttl})
18 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Solution:
 Identify hot counters with a key busy (error code 14) exception.
 Shard into several records <key||1> .. <key||N>. These will distribute to different nodes.
Reading the counter:
 How do you know if this counter is sharded? EAFP or Check ahead?
 EAFP approach:
 Overload the counter with a string. Assume all records aren't sharded.
 Catch any bin incompatible (error code 12) exception.
 Check-ahead approach:
 Check for the existence of a shard key with exists().
 If this counter is sharded, use a batch-read to fetch all the shards, and combine in the app.
Hot Counters
19 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05') -- : 🚀 U+1F680
And
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||1') -- : 14
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||2') -- : 11
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||3') -- : 9
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||4') -- : 12
('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||5') -- : 10
Either try to increment the original record and fail with an incompatible bin error (code 12), or check
for the existence of a shard key. One of those being true should lead to batch read the shard keys.
Hot Counters
20 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 In an AP system you have no guarantee that a write succeeded or failed on both the
master and replica, even when the cluster is stable (timeouts). It is best effort.
 Stale reads can happen from the slave before the transaction completes.
 Subsequent dirty reads if the write happens to one or both and a timeout occurs.
 An AP system will lose writes during network partitions.
 Aerospike 4.0 passed Jepsen testing of Strong Consistency (as did MongoDB,
CockroachDB).
 In a stable Aerospike 4 cluster with RF=2 the performance is the same as AP mode.
 If you want to be sure that your counters are accurate, you should use a namespace that is
defined as strong-consistency true.
Strong Consistency Mode
21 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
(Integer counter , Unordered Unique transactionIDs [ 1, 4, 7, 3, 9])
• Generate a transaction ID for each call. For example, use 4B for the client (process ID)
masked with a 4 byte transaction counter in the process.
1. In one transaction
a. Increment the counter value atomically.
b. list-prepend the transaction ID while declaring the list should be unique.
c. Trim the list to N recent transactions (by index).
d. Return the value of the counter.
2. If it succeeded then we’re done.
3. If it fails on a uniqueness violation for the transaction ID, then we’re done. This
transaction already happened (error code 24 ElementExistsError).
4. If the transaction is ‘inDoubt’ go to step 1.
Counters in Strong Consistency Mode
22 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … })
Cart: cartID => [ttl, status, quantity]
• This application handles ticket reservations for shows.
• A key identifies a specific show's inventory.
• Assume there is no assigned seating.
• The application should never overbook a show by selling more tickets than are available.
• The counter is the pair of seats remaining and shopping carts.
• When a show becomes available for booking, it is initialized with a number of seats.
• This example relies on Strong Consistency.
Ticket Inventory – Countdown to Zero
23 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )}
Cart: cartID => [ttl, status, quantity]
• Assuming that the most recently known seats quantity for the show was greater than
zero, you’d reserve seats with the following transaction:
1. Decrement the seats value.
2. map-set carts with the cart with aerospike.MAP_WRITE_FLAGS_CREATE_ONLY
3. Return the value of seats.
• If the reservation was 'inDoubt' repeat, then go to the next step on success or
ElementExistsError (error code 24).
Ticket Inventory – Countdown to Zero
24 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )}
Cart: cartID => [ttl, status, quantity]
• If the returned value is sub-zero, roll back with the transaction:
1. map-remove-by-key the cart ID from carts.
2. Increment seats by the cart quantity.
• If the rollback was 'inDoubt' check if the cart exists. If it does, repeat.
Ticket Inventory – Countdown to Zero
25 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )}
Cart: cartID => [ttl, status, quantity]
• If an item is removed from a cart, or the entire cart explicitly dumped, you’d read the value
of cartID in one map-get from the carts bin, then create a transaction to
1. map-remove-by-key the cartID from carts.
2. map-increment seats with the cart’s quantity.
• Periodically check for abandoned carts using a map-get-by-value( [ttl, WILDCARD] ) and
then treat each matched cart as if it was being explicitly removed.
• When a cart has been fully checked out, remove the map entry from carts , because the
inventory reservation is now permanent.
Ticket Inventory – Countdown to Zero
26 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
 We talked about the numeric data types in Aerospike.
 We modeled counters in Aerospike using different approaches.
 We talked about Strong Consistency mode.
 We discussed using Strong Consistency for implementing accurate counters.
What next?
 Take a look at the slides from the previous two Israeli ASUG meetups.
 Go to GitHub; clone the code samples repo; run it; read the code.
 Read the Aerospike blog. Get familiar with all the database features.
 Participate in the community forum (https://discuss.aerospike.com), StackOverflow’s
aerospike tag.
Summary
27 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.
Reference
 https://www.aerospike.com/docs/guide/data-types.html
 https://www.aerospike.com/docs/architecture/primary-index.html#single-bin-optimization
 https://www.aerospike.com/blog/aerospike-4-strong-consistency-and-jepsen/
 https://jepsen.io/consistency
 https://discuss.aerospike.com/t/handling-timeout-in-case-of-counter-bin/5196/4
 https://www.aerospike.com/docs/architecture/consistency.html#strong-consistency-mode
 https://www.aerospike.com/docs/guide/consistency.html#indoubt-errors
Code Samples
 https://github.com/rbotzer/aerospike-cdt-examples
Aerospike Training
 https://www.aerospike.com/training/
 https://academy.aerospike.com/
More material you can explore:
Thank You!
Any questions?
ronen@aerospike.com

More Related Content

What's hot

Neo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAltinity Ltd
 
Containerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeContainerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeDatabricks
 
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxData
 
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...Databricks
 
Kappa vs Lambda Architectures and Technology Comparison
Kappa vs Lambda Architectures and Technology ComparisonKappa vs Lambda Architectures and Technology Comparison
Kappa vs Lambda Architectures and Technology ComparisonKai Wähner
 
Design and Implementation of Incremental Cooperative Rebalancing
Design and Implementation of Incremental Cooperative RebalancingDesign and Implementation of Incremental Cooperative Rebalancing
Design and Implementation of Incremental Cooperative Rebalancingconfluent
 
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyMySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyContinuent
 
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...InfluxData
 
Optimizing Performance in Rust for Low-Latency Database Drivers
Optimizing Performance in Rust for Low-Latency Database DriversOptimizing Performance in Rust for Low-Latency Database Drivers
Optimizing Performance in Rust for Low-Latency Database DriversScyllaDB
 
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, Adjust
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, AdjustShipping Data from Postgres to Clickhouse, by Murat Kabilov, Adjust
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, AdjustAltinity Ltd
 
Introduction to DataFusion An Embeddable Query Engine Written in Rust
Introduction to DataFusion  An Embeddable Query Engine Written in RustIntroduction to DataFusion  An Embeddable Query Engine Written in Rust
Introduction to DataFusion An Embeddable Query Engine Written in RustAndrew Lamb
 
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...Christian Posta
 
Owning Your Own (Data) Lake House
Owning Your Own (Data) Lake HouseOwning Your Own (Data) Lake House
Owning Your Own (Data) Lake HouseData Con LA
 
Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityApache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityWes McKinney
 
Building Data Intensive Analytic Application on Top of Delta Lakes
Building Data Intensive Analytic Application on Top of Delta LakesBuilding Data Intensive Analytic Application on Top of Delta Lakes
Building Data Intensive Analytic Application on Top of Delta LakesDatabricks
 
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...StreamNative
 
High Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouseHigh Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouseAltinity Ltd
 

What's hot (20)

Neo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j Drivers Best Practices
Neo4j Drivers Best Practices
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdf
 
Containerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeContainerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta Lake
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
 
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
 
Kappa vs Lambda Architectures and Technology Comparison
Kappa vs Lambda Architectures and Technology ComparisonKappa vs Lambda Architectures and Technology Comparison
Kappa vs Lambda Architectures and Technology Comparison
 
Design and Implementation of Incremental Cooperative Rebalancing
Design and Implementation of Incremental Cooperative RebalancingDesign and Implementation of Incremental Cooperative Rebalancing
Design and Implementation of Incremental Cooperative Rebalancing
 
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware companyMySQL High Availability and Disaster Recovery with Continuent, a VMware company
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
 
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
 
Optimizing Performance in Rust for Low-Latency Database Drivers
Optimizing Performance in Rust for Low-Latency Database DriversOptimizing Performance in Rust for Low-Latency Database Drivers
Optimizing Performance in Rust for Low-Latency Database Drivers
 
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, Adjust
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, AdjustShipping Data from Postgres to Clickhouse, by Murat Kabilov, Adjust
Shipping Data from Postgres to Clickhouse, by Murat Kabilov, Adjust
 
Introduction to DataFusion An Embeddable Query Engine Written in Rust
Introduction to DataFusion  An Embeddable Query Engine Written in RustIntroduction to DataFusion  An Embeddable Query Engine Written in Rust
Introduction to DataFusion An Embeddable Query Engine Written in Rust
 
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...
Leveraging Envoy Proxy and GraphQL to Lower the Risk of Monolith to Microserv...
 
Owning Your Own (Data) Lake House
Owning Your Own (Data) Lake HouseOwning Your Own (Data) Lake House
Owning Your Own (Data) Lake House
 
Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityApache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
 
Building Data Intensive Analytic Application on Top of Delta Lakes
Building Data Intensive Analytic Application on Top of Delta LakesBuilding Data Intensive Analytic Application on Top of Delta Lakes
Building Data Intensive Analytic Application on Top of Delta Lakes
 
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
 
High Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouseHigh Performance, High Reliability Data Loading on ClickHouse
High Performance, High Reliability Data Loading on ClickHouse
 
Greenplum Roadmap
Greenplum RoadmapGreenplum Roadmap
Greenplum Roadmap
 

Similar to Countdown to Zero - Counter Use Cases in Aerospike

InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxData
 
Virtual training Intro to Kapacitor
Virtual training  Intro to Kapacitor Virtual training  Intro to Kapacitor
Virtual training Intro to Kapacitor InfluxData
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
OPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKOPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKInfluxData
 
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019Codemotion
 
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...InfluxData
 
20181025_pgconfeu_lt_gstorefdw
20181025_pgconfeu_lt_gstorefdw20181025_pgconfeu_lt_gstorefdw
20181025_pgconfeu_lt_gstorefdwKohei KaiGai
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresConnor McDonald
 
AMD Next Horizon
AMD Next HorizonAMD Next Horizon
AMD Next HorizonAMD
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction Netronome
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cConnor McDonald
 
Syngenta's Predictive Analytics Platform for Seeds R&D
Syngenta's Predictive Analytics Platform for Seeds R&DSyngenta's Predictive Analytics Platform for Seeds R&D
Syngenta's Predictive Analytics Platform for Seeds R&DMichael Swanson
 
Predicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningPredicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningCarol McDonald
 
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with Fargate
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with FargateDEM07 Best Practices for Monitoring Amazon ECS Containers Launched with Fargate
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with FargateAmazon Web Services
 
Iperconvergenza come migliora gli economics del tuo IT
Iperconvergenza come migliora gli economics del tuo ITIperconvergenza come migliora gli economics del tuo IT
Iperconvergenza come migliora gli economics del tuo ITNetApp
 
Hash join use memory optimization
Hash join use memory optimizationHash join use memory optimization
Hash join use memory optimizationICTeam S.p.A.
 

Similar to Countdown to Zero - Counter Use Cases in Aerospike (20)

InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
 
Virtual training Intro to Kapacitor
Virtual training  Intro to Kapacitor Virtual training  Intro to Kapacitor
Virtual training Intro to Kapacitor
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
OPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKOPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACK
 
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019
Pablo Musa - Managing your Black Friday Logs - Codemotion Amsterdam 2019
 
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...
Jacob Marble [InfluxData] | Observability with InfluxDB IOx and OpenTelemetry...
 
Poc exadata 2018
Poc exadata 2018Poc exadata 2018
Poc exadata 2018
 
20181025_pgconfeu_lt_gstorefdw
20181025_pgconfeu_lt_gstorefdw20181025_pgconfeu_lt_gstorefdw
20181025_pgconfeu_lt_gstorefdw
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c features
 
vSZ Demo
vSZ DemovSZ Demo
vSZ Demo
 
AMD Next Horizon
AMD Next HorizonAMD Next Horizon
AMD Next Horizon
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
Syngenta's Predictive Analytics Platform for Seeds R&D
Syngenta's Predictive Analytics Platform for Seeds R&DSyngenta's Predictive Analytics Platform for Seeds R&D
Syngenta's Predictive Analytics Platform for Seeds R&D
 
Predicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningPredicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine Learning
 
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with Fargate
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with FargateDEM07 Best Practices for Monitoring Amazon ECS Containers Launched with Fargate
DEM07 Best Practices for Monitoring Amazon ECS Containers Launched with Fargate
 
Iperconvergenza come migliora gli economics del tuo IT
Iperconvergenza come migliora gli economics del tuo ITIperconvergenza come migliora gli economics del tuo IT
Iperconvergenza come migliora gli economics del tuo IT
 
Hash join use memory optimization
Hash join use memory optimizationHash join use memory optimization
Hash join use memory optimization
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

Countdown to Zero - Counter Use Cases in Aerospike

  • 1. Countdown to Zero Counter Use Cases in Aerospike
  • 2. 2 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  I’m Ronen Botzer, and I’m a solutions architect at Aerospike.  I’ve worked at Aerospike since June 2014, first on the Python and PHP clients.  I’m active on StackOverflow and the Aerospike community forum.  This is the third in a series of tech talks about data modeling.  Check out the slides from the previous ASUG Israel meetups. Welcome to Aerospike User Group Israel #3
  • 3. 3 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  A Quick Overview of Aerospike Data Model and Storage  Counter Use Cases  Data Capping – Telecom  Frequency Capping – Ad Tech  Consolidating Counters  Mitigating Hot Counters  Strong Consistency  Counters  Ticket Inventory – Countdown to Zero  Summary Agenda
  • 4. 4 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Aerospike is a Primary Key Database Objects stored in Aerospike are called records A bin holds the value of a supported data type: integer, double, string, bytes, list, map, geospatial Every record is uniquely identified by the 3-tuple (namespace, set, user-key) A record contains one or more bins (namespace, set, user-key) EXP – Expiration Timestamp LUT – Last Update Time GEN – Generation RECORD EXP LUT GEN BIN1 BIN2
  • 5. 5 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  Aerospike is a row-oriented distributed database  Rows (records) contain one or more columns (bins)  Similar to an RDBMS with primary-key table lookups  Single record transactions  Namespaces can be configured for strong consistency Aerospike Concepts Aerospike RDBMS Namespace Tablespace or Database Set Table Record Row Bin Column Bin type Integer Double String Bytes List (Unordered, Ordered) Map (Unordered, K-Ordered, KV-Ordered) GeoJSON
  • 6. 6 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  Integer  8B of storage (64-bit)  In places where signed values are needed (secondary indexes) the integer is signed in the range of –(2^63) to (2^63) – 1.  Double  64-bit IEEE-754  Both Integer and Double values can be used for counters.  Support the atomic increment() operation.  Can be stored in special data-in-index namespaces. Numeric Data Types in Aerospike
  • 7. 7 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Namespace Storage
  • 8. 8 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Data Capping namespace users { memory-size 80G replication-factor 2 prefer-uniform-balance true partition-tree-sprigs 8192 storage-engine device { write-block-size 128K data-in-memory false read-page-cache true post-write-queue 1024 write-block-size 128K device /dev/nvme1n1p1 device /dev/nvme1n1p2 device /dev/nvme1n1p3 device /dev/nvme2n1p1 device /dev/nvme2n1p2 device /dev/nvme2n1p3 } }
  • 9. 9 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. ('users', 'mobile', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2') -- name: 'Jasper Madison Jr.' age: 27 payment-method: [ { 'type': 'visa', 'last4’: 6164, 'expires': '2019-09'}, { 'type': 'mastercard', 'last4': 7147, 'expires': '2023-03'} ] number: [ 1, 408, 5551212 ] data: 10711339520  Atomically increment() the integer value of data to implement a counter  What's the problem with this approach? Data Capping
  • 10. 10 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  Think about the access patterns.  The naive implementation has the user's data stored in a single record.  Minimizes the amount of memory used by this namespace.  Reduces the number of reads.  Problem: the data counter updates frequently.  Solution: split the data counter into a separate in-memory namespace.  Consider using the data-in-index optimization. Optimizing Counters – Namespace Considerations
  • 11. 11 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Optimizing Counters – Namespace Considerations namespace counters { memory-size 20G default-ttl 1d replication-factor 2 partition-tree-sprigs 8192 prefer-uniform-balance true single-bin true data-in-index true storage-engine device { data-in-memory true filesize 40G write-block-size 256K file /opt/aerospike/data/counters.dat } }
  • 12. 12 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. ('counters', 'mobdata', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|2019-02') -- : 10711339520 • Initialize this record with an explicit 0 value each month • On all writes (each increment) set the TTL to -1, i.e. NEVER_EXPIRE • Combine the increment with a read. After every update the app knows the latest value • Archive the counter after rolling to the new month Data Capping – Counter Using Data in Index
  • 13. 13 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. from aerospike_helpers.operations import operations as oh key = ('counters', mobdata', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|2019-02') ops = [ oh.increment('', 1500), oh.read('') ] ttl = aerospike.TTL_NEVER_EXPIRE # AKA ttl -1 (key, meta, bins) = client.operate(key, ops, {'ttl': ttl}, {'timeout': 50}) Data Capping – Increment and Read in a single Transaction
  • 14. 14 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05') -- : 3  Keep track of ads served to a user in a given day.  Compound key of userID | adID | day  Increment should work as an upsert.  Initial TTL of 24 hours (use the default TTL of 1 day).  Do not update the TTL if the record exists, by setting it to -2. Frequency Capping
  • 15. 15 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Frequency Capping from aerospike import exception as e key = ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05') try: (key, meta, bins) = client.get(key, {'timeout': 20}) if bins[''] < AD_LIMIT: client.increment(key, '', 1, {'ttl': aerospike.TTL_DONT_UPDATE}) # aka ttl -2 # continue and attempt to serve the ad except e.RecordNotFound: ttl = aerospike.TTL_NAMESPACE_DEFAULT # AKA ttl 0, inherit the default-ttl client.put(key, '', 1, {'ttl': ttl}, policy={'exists': aerospike.POLICY_EXISTS_CREATE})
  • 16. 16 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|cmp123|2019-03-05') -- : { 'adx123': 2, 'adx456': 3 }  Keep track of all campaign ads served to a user in a given day  Compound key of userID | campaignID | day  Map increment should work as an upsert, returning the current count  Initial TTL of 24 hours (default TTL is 1 day)  Do not update the TTL if the record exists, by setting it to -2.  Only numeric data works with data-in-index. Use data-in-memory/single-bin. Frequency Capping – Consolidating Counters
  • 17. 17 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Frequency Capping – Consolidating Counters key = ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|cmp123|2019-03-05') try: val = client.map_get_by_key(key, 'ads', 'adx123', aerospike.MAP_RETURN_VALUE) if val < AD_LIMIT: # continue and attempt to serve the ad client.map_increment(key, '', 'adx123', 1, {}, {'ttl': aerospike.TTL_DONT_UPDATE}) except e.RecordNotFound as err: try: ops = [ mh.map_put('', 'adx123', 1, {}), mh.map_get_by_key('', 'adx123', aerospike.MAP_RETURN_VALUE) ] ttl = aerospike.TTL_NAMESPACE_DEFAULT # AKA ttl 0, inherit the default-ttl (key, meta, bins) = client.operate(key, ops, {'ttl': ttl})
  • 18. 18 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Solution:  Identify hot counters with a key busy (error code 14) exception.  Shard into several records <key||1> .. <key||N>. These will distribute to different nodes. Reading the counter:  How do you know if this counter is sharded? EAFP or Check ahead?  EAFP approach:  Overload the counter with a string. Assume all records aren't sharded.  Catch any bin incompatible (error code 12) exception.  Check-ahead approach:  Check for the existence of a shard key with exists().  If this counter is sharded, use a batch-read to fetch all the shards, and combine in the app. Hot Counters
  • 19. 19 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05') -- : 🚀 U+1F680 And ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||1') -- : 14 ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||2') -- : 11 ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||3') -- : 9 ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||4') -- : 12 ('counters', 'adcap', 'cf296d9a-0b77-4dd0-8d2b-91e59a6f02d2|adx123|2019-03-05||5') -- : 10 Either try to increment the original record and fail with an incompatible bin error (code 12), or check for the existence of a shard key. One of those being true should lead to batch read the shard keys. Hot Counters
  • 20. 20 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  In an AP system you have no guarantee that a write succeeded or failed on both the master and replica, even when the cluster is stable (timeouts). It is best effort.  Stale reads can happen from the slave before the transaction completes.  Subsequent dirty reads if the write happens to one or both and a timeout occurs.  An AP system will lose writes during network partitions.  Aerospike 4.0 passed Jepsen testing of Strong Consistency (as did MongoDB, CockroachDB).  In a stable Aerospike 4 cluster with RF=2 the performance is the same as AP mode.  If you want to be sure that your counters are accurate, you should use a namespace that is defined as strong-consistency true. Strong Consistency Mode
  • 21. 21 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. (Integer counter , Unordered Unique transactionIDs [ 1, 4, 7, 3, 9]) • Generate a transaction ID for each call. For example, use 4B for the client (process ID) masked with a 4 byte transaction counter in the process. 1. In one transaction a. Increment the counter value atomically. b. list-prepend the transaction ID while declaring the list should be unique. c. Trim the list to N recent transactions (by index). d. Return the value of the counter. 2. If it succeeded then we’re done. 3. If it fails on a uniqueness violation for the transaction ID, then we’re done. This transaction already happened (error code 24 ElementExistsError). 4. If the transaction is ‘inDoubt’ go to step 1. Counters in Strong Consistency Mode
  • 22. 22 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … }) Cart: cartID => [ttl, status, quantity] • This application handles ticket reservations for shows. • A key identifies a specific show's inventory. • Assume there is no assigned seating. • The application should never overbook a show by selling more tickets than are available. • The counter is the pair of seats remaining and shopping carts. • When a show becomes available for booking, it is initialized with a number of seats. • This example relies on Strong Consistency. Ticket Inventory – Countdown to Zero
  • 23. 23 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )} Cart: cartID => [ttl, status, quantity] • Assuming that the most recently known seats quantity for the show was greater than zero, you’d reserve seats with the following transaction: 1. Decrement the seats value. 2. map-set carts with the cart with aerospike.MAP_WRITE_FLAGS_CREATE_ONLY 3. Return the value of seats. • If the reservation was 'inDoubt' repeat, then go to the next step on success or ElementExistsError (error code 24). Ticket Inventory – Countdown to Zero
  • 24. 24 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )} Cart: cartID => [ttl, status, quantity] • If the returned value is sub-zero, roll back with the transaction: 1. map-remove-by-key the cart ID from carts. 2. Increment seats by the cart quantity. • If the rollback was 'inDoubt' check if the cart exists. If it does, repeat. Ticket Inventory – Countdown to Zero
  • 25. 25 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Shows (Integer seats , Unordered Unique carts { c1, c2, c3, c4, … )} Cart: cartID => [ttl, status, quantity] • If an item is removed from a cart, or the entire cart explicitly dumped, you’d read the value of cartID in one map-get from the carts bin, then create a transaction to 1. map-remove-by-key the cartID from carts. 2. map-increment seats with the cart’s quantity. • Periodically check for abandoned carts using a map-get-by-value( [ttl, WILDCARD] ) and then treat each matched cart as if it was being explicitly removed. • When a cart has been fully checked out, remove the map entry from carts , because the inventory reservation is now permanent. Ticket Inventory – Countdown to Zero
  • 26. 26 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc.  We talked about the numeric data types in Aerospike.  We modeled counters in Aerospike using different approaches.  We talked about Strong Consistency mode.  We discussed using Strong Consistency for implementing accurate counters. What next?  Take a look at the slides from the previous two Israeli ASUG meetups.  Go to GitHub; clone the code samples repo; run it; read the code.  Read the Aerospike blog. Get familiar with all the database features.  Participate in the community forum (https://discuss.aerospike.com), StackOverflow’s aerospike tag. Summary
  • 27. 27 Proprietary & Confidential | All rights reserved. © 2018 Aerospike Inc. Reference  https://www.aerospike.com/docs/guide/data-types.html  https://www.aerospike.com/docs/architecture/primary-index.html#single-bin-optimization  https://www.aerospike.com/blog/aerospike-4-strong-consistency-and-jepsen/  https://jepsen.io/consistency  https://discuss.aerospike.com/t/handling-timeout-in-case-of-counter-bin/5196/4  https://www.aerospike.com/docs/architecture/consistency.html#strong-consistency-mode  https://www.aerospike.com/docs/guide/consistency.html#indoubt-errors Code Samples  https://github.com/rbotzer/aerospike-cdt-examples Aerospike Training  https://www.aerospike.com/training/  https://academy.aerospike.com/ More material you can explore:

Editor's Notes

  1. We’ll start with a recap from the beginning of my previous talk
  2. In an RDBMS we connect to a database. In that database we have tables containing rows. Each row will typically have a primary key that uniquely identifies it Rows contain one or more columns of a supported data types Most applications avoid entity-relationship purity for access speed, denormalizing into a single table, and accessed by primary-key lookup
  3. Records are stored contiguously Records are grouped together into blocks and written in a single write operation to disk The block size is controlled by the write-block-size config parameter This applies to both raw device and file-based storage The records are first placed in a streaming write buffer – a block in-memory of the same size as the write block The SWB is flushed to disk when the block is full or when flush-max-ms is hit. Or every time if commit-to-device true The primary index is updated. For each record being written Aerospike notes the device/file, the block ID, byte offset Therefore any record can be reached with a single read IO
  4. Assume many other bins – address, bills, payment history, etc, this object is 2K roughly If there are 400M users storage is over ten billion bytes, almost 10GiB
  5. In hybrid-memory mode (primary index in process memory or shared memory) Aerospike uses 64B of DRAM per-record Less reads so we get the result faster, only if we always fetch all the data Since most operations will be updates and not reads, there's a benefit to splitting them. Also the updates operate on a much smaller object reducing disk IO
  6. For 400M objects we're using 8192 sprigs, memory overhead of 848MiB evenly distributed over the number of nodes 8B storage for numeric (integer, double) data Removes all bin related overhead How much memory does this take in Aerospike 4.2 or higher? How much storage space? (as low as 48B, typically 64B with short set name)
  7. Create the monthly data counters ahead of time
  8. If RecordNotFound you can also set it to any explicit TTL such as 24h, rather than use default-TTL
  9. This is the opposite of consolidating counters into a single record. This is a more complex solution, separating into an in-memory or data-in-index namespace. In some languages exception handling is very heavy (Java), in others you are encouraged to EAFP – try first, handle the exception.
  10. If you search redislabs 'strong consistency' on Google the term comes up in the search results, but magically it doesn't appear in the page itself. That's 'solving' a technical gap with marketing and SEO. Some competitors use 'strong eventual consistency'. That is a form of weak consistency. As a metaphor you know Golden State Warriors? 1st place in Western Conference of the NBA. Do you know Santa Cruz Warriors? 1st place in the G-League with .707 win/total ratio (better than Golden State). However, it's 1st place in the G-League, not the NBA. Write went to the master, master wrote to the slave, master dies. The state on the slave is now different, and it doesn't know the master died. The slave is promoted but the write failed. Any read now before the client acts (to write again or not write again) is an unexpected value. The client might try to repeat the write again and modify not the previous state but the current one.
  11. A strongly consistent counter is modeled with a pair of bins – an integer counter and an unordered list of unique transaction IDs.
  12. A strongly consistent counter is modeled with a pair of bins – an integer counter and an unordered list of unique transaction IDs.
  13. A strongly consistent counter is modeled with a pair of bins – an integer counter and an unordered list of unique transaction IDs.
  14. A strongly consistent counter is modeled with a pair of bins – an integer counter and an unordered list of unique transaction IDs.
  15. Removing a cart is exactly like a rollback when there aren't enough seats.
  16. More of these to come
  17. New and renewing EE users, and anyone signed up to download CE gets academy access.