SlideShare a Scribd company logo
Redis as a Time Series DB
Josiah Carlson - @dr_josiah
Agenda
● Who are you?
● What is Redis? (3 minutes, optional)
● What is a time series database?
● Combining structures for success
● Analyzing/segmenting events
● Next steps
● Questions
Who are you?
● A guy who does a lot of stuff with Redis and Python
○ Book:
■ Redis in Action http://manning.com/carlson
■ Read for free http://bit.ly/ria-free
○ Libraries: https://github.com/josiahcarlson
■ rom, RPQueue, lua_call, parse-crontab, …
○ Mailing list: https://groups.google.com/forum/#!forum/redis-db (not active here recently)
○ Blog: dr-josiah.com
○ Twitter: @dr_josiah
What is Redis?
● In-memory key/data structure server
○ Strings, lists, hashes, sets, sorted sets (plus integers and floats)
○ HyperLogLog, lexicographic prefix scans, geo index/search api (unreleased 3.2)
○ Pubsub, Lua scripting (like a stored procedure)
● Ops features:
○ Master/slave replication + sentinel for HA
○ Alternative “cluster” mode with sharding/slaving/failover
○ On-disk persistence; point-in-time or incremental
What is a time series database?
● Not about the database, but about the data and operations
○ Discrete events or samples of at least one value or metric over time
○ Sometimes the *event* is the value/metric
○ If it has a timestamp (or one is implied), it is part of a time series
● Examples of data:
○ Data gathered from sensors embedded inside IoT devices
■ Nest thermostat - measures temperature, analyzes your preferences…
○ Sell prices and volumes of traded stocks
○ Values and delivery locations of orders placed at an online retailer
○ Actions of users in a video game and their outcome
Combining structures for success
● Consider a log of user actions on a web site like:
○ {‘ts’: 1458710360.679, ‘user’: 218946, ‘type’: ‘login’, ‘ip’: ‘172.32.5.6’}
● We can get an easily sliced time series with individual events stored in hashes,
and a sorted set for an index of timestamps:
○ Increment the actions: key, which becomes the event id
○ Store each event individually in its own HASH at key: actions:<event_id>
○ Add an (<event_id>: <ts>) member/score pair to a ZSET at key: actions:ts
● To use:
○ Scan over actions:ts using ZRANGEBYSCORE or ZRANGE
○ Use HGET/HMGET/HGETALL to fetch the actions for analysis
Combining structures for success (reading)
-- Many-caveats about using this, you probably don't want it (not cluster compatible)!
-- KEYS should be something like:
-- {'action:ts', 'action:'}
-- ARGV should be something like:
-- (gets all events from 2016-03-23 UTC)
-- {'1458691200', '1458777600'}
local ids = redis.call('ZRANGEBYSCORE', KEYS[1], unpack(ARGV))
local results = {}
for i, id in ipairs(ids) do
local item = redis.call('HGETALL', KEYS[2]..id)
if item then
table.insert(results, item)
end
end
return cjson.encode(results)
Combining structures for success (writing)
-- Many-caveats about using this, you probably don't want it (not cluster compatible)!
-- KEYS should be something like:
-- {'action:'}
-- ARGV should be something like:
-- {'<json-encoded data, with ts>'}
local new_id = redis.call('INCR', KEYS[1])
local dest = KEYS[1] .. new_id
local data = cjson.decode(ARGV[1])
data.id = new_id
for k, v in pairs(data) do
redis.call('HSET', dest, k, v)
end
-- note: ZADD <key> <score> <member>
redis.call('ZADD', KEYS[1] .. 'ts', data.ts, new_id)
Analyzing/segmenting events
We now have events, but want to (for example) count the number of events of
different types in a time range, equivalent to:
SELECT type, COUNT(*)
FROM actions
WHERE …
GROUP BY type
● We can use Lua to scan over the items in the time range, counting them
● We can create additional ZSETs, one for each event type…
○ actions:login:ts, actions:logout:ts, …
○ Stores (<event_id>: <ts>) pairs, like actions:ts
○ Can use ZCOUNT to get a count without scanning*
Analyzing/segmenting events (continued)
● Or if you needed to index events by user id
○ Add (<event_id>, <user_id>) member/score pairs to actions:user
○ Easy to get total count/user with ZCOUNT (ZCOUNT actions:user <user_id> <user_id>)
○ Can partially induce a secondary timestamp index over the same data; to fetch a specific time
range for one user
■ Use ZRANGEBYSCORE and ZREVRANGEBYSCORE on actions:ts for start/end of id
range for a pair of timestamps (assuming synchronized clocks, or using Redis 3.2-
unreleased Lua side-effects propagation)
■ Either:
● Use ZRANGEBYSCORE on actions:user to scan ids and filter
● Use ZRANGEBYSCORE + ZREVRANGEBYSCORE + ZRANGE to bisect (speed
optimization, requires left padding of members with zeros)
Combining structures for success (revisited)
● If you know you never need to extract individual fields, and you know that your
events are unique…
○ Use a single ZSET with (<encoded json event>: <ts>) pairs
● If you are planning on bucketing based on time slot, only need a list of items
○ Use LISTs keyed as actions:<time slice>
○ Just RPUSH <encoded json event> onto these LISTs
● Approximate counts? HyperLogLog
● If you plan your metrics, you can explicitly count them in real time
○ INCR, DECR, INCRBY, INCRBYFLOAT, HINCRBY, HINCRBYFLOAT, ZINCRBY, all very fast
○ Lua scripting can be a huge win here
Combining structures for success (revisited)
● Redis doesn’t need to be 100% of this
○ If you only need counts over arbitrary time ranges, just action:ts or the action:login:ts
and related sorted sets may be enough
○ Redis can be your counters/aggregate/sorted set storage, even if it’s not your event storage
● HASHes + ZSETs can solve just about anything, alternatives can offer:
○ Better performance
○ More convenient access to necessary data
○ Lower memory utilization
Next steps
Time series is a specific example of data modeling...
● My data modeling talk from Redisconf 2015
○ Get an idea of the general process involved
● Specific examples:
○ For indexing/search: chapter 7 of RiA, my Redisconf 2012 talk
○ Other data modeling examples: the rest of RiA, my blog
○ Survey of data modeling examples: my Python with Redis talk from July 2012
● Google will know more
Questions?
Josiah Carlson - @dr_josiah

More Related Content

Viewers also liked

Lambda architecture on Spark, Kafka for real-time large scale ML
Lambda architecture on Spark, Kafka for real-time large scale MLLambda architecture on Spark, Kafka for real-time large scale ML
Lambda architecture on Spark, Kafka for real-time large scale ML
huguk
 
Redis and its many use cases
Redis and its many use casesRedis and its many use cases
Redis and its many use cases
Christian Joudrey
 
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Redis Labs
 
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of LuaRedis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Itamar Haber
 
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Maarten Balliauw
 
Use Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual WaysUse Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual Ways
Itamar Haber
 
Getting Started with Redis
Getting Started with RedisGetting Started with Redis
Getting Started with Redis
Faisal Akber
 
UV logic using redis bitmap
UV logic using redis bitmapUV logic using redis bitmap
UV logic using redis bitmap
주용 오
 
RespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShellRespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShell
Yoshifumi Kawai
 
HIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoProHIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoPro
Redis Labs
 
Introduction to some top Redis use cases
Introduction to some top Redis use casesIntroduction to some top Redis use cases
Introduction to some top Redis use cases
Josiah Carlson
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
Redis Labs
 
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulRedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
DynomiteDB
 
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre... Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Redis Labs
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with Redis
Avram Lyon
 
Velox at SF Data Mining Meetup
Velox at SF Data Mining MeetupVelox at SF Data Mining Meetup
Velox at SF Data Mining Meetup
Dan Crankshaw
 
Cloud Foundry for Data Science
Cloud Foundry for Data ScienceCloud Foundry for Data Science
Cloud Foundry for Data Science
Ian Huston
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Itamar Haber
 
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalBack your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Redis Labs
 

Viewers also liked (20)

Lambda architecture on Spark, Kafka for real-time large scale ML
Lambda architecture on Spark, Kafka for real-time large scale MLLambda architecture on Spark, Kafka for real-time large scale ML
Lambda architecture on Spark, Kafka for real-time large scale ML
 
Redis use cases
Redis use casesRedis use cases
Redis use cases
 
Redis and its many use cases
Redis and its many use casesRedis and its many use cases
Redis and its many use cases
 
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
 
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of LuaRedis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of Lua
 
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
 
Use Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual WaysUse Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual Ways
 
Getting Started with Redis
Getting Started with RedisGetting Started with Redis
Getting Started with Redis
 
UV logic using redis bitmap
UV logic using redis bitmapUV logic using redis bitmap
UV logic using redis bitmap
 
RespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShellRespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShell
 
HIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoProHIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoPro
 
Introduction to some top Redis use cases
Introduction to some top Redis use casesIntroduction to some top Redis use cases
Introduction to some top Redis use cases
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
 
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulRedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
 
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre... Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with Redis
 
Velox at SF Data Mining Meetup
Velox at SF Data Mining MeetupVelox at SF Data Mining Meetup
Velox at SF Data Mining Meetup
 
Cloud Foundry for Data Science
Cloud Foundry for Data ScienceCloud Foundry for Data Science
Cloud Foundry for Data Science
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
 
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalBack your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
 

Similar to March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB

Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
Mukesh Singh
 
NoSQL Solutions - a comparative study
NoSQL Solutions - a comparative studyNoSQL Solutions - a comparative study
NoSQL Solutions - a comparative studyGuillaume Lefranc
 
Security Monitoring for big Infrastructures without a Million Dollar budget
Security Monitoring for big Infrastructures without a Million Dollar budgetSecurity Monitoring for big Infrastructures without a Million Dollar budget
Security Monitoring for big Infrastructures without a Million Dollar budget
Juan Berner
 
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Hernan Costante
 
Druid
DruidDruid
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Hakka Labs
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
Demi Ben-Ari
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
 
Monitoring microservices with Prometheus
Monitoring microservices with PrometheusMonitoring microservices with Prometheus
Monitoring microservices with Prometheus
Tobias Schmidt
 
Neo4j after 1 year in production
Neo4j after 1 year in productionNeo4j after 1 year in production
Neo4j after 1 year in production
Andrew Nikishaev
 
Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?
Huy Nguyen
 
Big data @ uber vu (1)
Big data @ uber vu (1)Big data @ uber vu (1)
Big data @ uber vu (1)Mihnea Giurgea
 
Data pipelines from zero to solid
Data pipelines from zero to solidData pipelines from zero to solid
Data pipelines from zero to solid
Lars Albertsson
 
Logging and ranting / Vytis Valentinavičius (Lamoda)
Logging and ranting / Vytis Valentinavičius (Lamoda)Logging and ranting / Vytis Valentinavičius (Lamoda)
Logging and ranting / Vytis Valentinavičius (Lamoda)
Ontico
 
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
NETWAYS
 
OpenTSDB 2.0
OpenTSDB 2.0OpenTSDB 2.0
OpenTSDB 2.0
HBaseCon
 
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
Codemotion
 
Aggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of dataAggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of data
Rostislav Pashuto
 
Piano Media - approach to data gathering and processing
Piano Media - approach to data gathering and processingPiano Media - approach to data gathering and processing
Piano Media - approach to data gathering and processing
MartinStrycek
 
Amazon Redshift
Amazon RedshiftAmazon Redshift
Amazon Redshift
Jeff Patti
 

Similar to March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB (20)

Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
NoSQL Solutions - a comparative study
NoSQL Solutions - a comparative studyNoSQL Solutions - a comparative study
NoSQL Solutions - a comparative study
 
Security Monitoring for big Infrastructures without a Million Dollar budget
Security Monitoring for big Infrastructures without a Million Dollar budgetSecurity Monitoring for big Infrastructures without a Million Dollar budget
Security Monitoring for big Infrastructures without a Million Dollar budget
 
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
 
Druid
DruidDruid
Druid
 
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
Monitoring microservices with Prometheus
Monitoring microservices with PrometheusMonitoring microservices with Prometheus
Monitoring microservices with Prometheus
 
Neo4j after 1 year in production
Neo4j after 1 year in productionNeo4j after 1 year in production
Neo4j after 1 year in production
 
Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?
 
Big data @ uber vu (1)
Big data @ uber vu (1)Big data @ uber vu (1)
Big data @ uber vu (1)
 
Data pipelines from zero to solid
Data pipelines from zero to solidData pipelines from zero to solid
Data pipelines from zero to solid
 
Logging and ranting / Vytis Valentinavičius (Lamoda)
Logging and ranting / Vytis Valentinavičius (Lamoda)Logging and ranting / Vytis Valentinavičius (Lamoda)
Logging and ranting / Vytis Valentinavičius (Lamoda)
 
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
OSMC 2018 | Learnings, patterns and Uber’s metrics platform M3, open sourced ...
 
OpenTSDB 2.0
OpenTSDB 2.0OpenTSDB 2.0
OpenTSDB 2.0
 
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
Managing your Black Friday Logs - Antonio Bonuccelli - Codemotion Rome 2018
 
Aggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of dataAggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of data
 
Piano Media - approach to data gathering and processing
Piano Media - approach to data gathering and processingPiano Media - approach to data gathering and processing
Piano Media - approach to data gathering and processing
 
Amazon Redshift
Amazon RedshiftAmazon Redshift
Amazon Redshift
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB

  • 1. Redis as a Time Series DB Josiah Carlson - @dr_josiah
  • 2. Agenda ● Who are you? ● What is Redis? (3 minutes, optional) ● What is a time series database? ● Combining structures for success ● Analyzing/segmenting events ● Next steps ● Questions
  • 3. Who are you? ● A guy who does a lot of stuff with Redis and Python ○ Book: ■ Redis in Action http://manning.com/carlson ■ Read for free http://bit.ly/ria-free ○ Libraries: https://github.com/josiahcarlson ■ rom, RPQueue, lua_call, parse-crontab, … ○ Mailing list: https://groups.google.com/forum/#!forum/redis-db (not active here recently) ○ Blog: dr-josiah.com ○ Twitter: @dr_josiah
  • 4. What is Redis? ● In-memory key/data structure server ○ Strings, lists, hashes, sets, sorted sets (plus integers and floats) ○ HyperLogLog, lexicographic prefix scans, geo index/search api (unreleased 3.2) ○ Pubsub, Lua scripting (like a stored procedure) ● Ops features: ○ Master/slave replication + sentinel for HA ○ Alternative “cluster” mode with sharding/slaving/failover ○ On-disk persistence; point-in-time or incremental
  • 5. What is a time series database? ● Not about the database, but about the data and operations ○ Discrete events or samples of at least one value or metric over time ○ Sometimes the *event* is the value/metric ○ If it has a timestamp (or one is implied), it is part of a time series ● Examples of data: ○ Data gathered from sensors embedded inside IoT devices ■ Nest thermostat - measures temperature, analyzes your preferences… ○ Sell prices and volumes of traded stocks ○ Values and delivery locations of orders placed at an online retailer ○ Actions of users in a video game and their outcome
  • 6. Combining structures for success ● Consider a log of user actions on a web site like: ○ {‘ts’: 1458710360.679, ‘user’: 218946, ‘type’: ‘login’, ‘ip’: ‘172.32.5.6’} ● We can get an easily sliced time series with individual events stored in hashes, and a sorted set for an index of timestamps: ○ Increment the actions: key, which becomes the event id ○ Store each event individually in its own HASH at key: actions:<event_id> ○ Add an (<event_id>: <ts>) member/score pair to a ZSET at key: actions:ts ● To use: ○ Scan over actions:ts using ZRANGEBYSCORE or ZRANGE ○ Use HGET/HMGET/HGETALL to fetch the actions for analysis
  • 7. Combining structures for success (reading) -- Many-caveats about using this, you probably don't want it (not cluster compatible)! -- KEYS should be something like: -- {'action:ts', 'action:'} -- ARGV should be something like: -- (gets all events from 2016-03-23 UTC) -- {'1458691200', '1458777600'} local ids = redis.call('ZRANGEBYSCORE', KEYS[1], unpack(ARGV)) local results = {} for i, id in ipairs(ids) do local item = redis.call('HGETALL', KEYS[2]..id) if item then table.insert(results, item) end end return cjson.encode(results)
  • 8. Combining structures for success (writing) -- Many-caveats about using this, you probably don't want it (not cluster compatible)! -- KEYS should be something like: -- {'action:'} -- ARGV should be something like: -- {'<json-encoded data, with ts>'} local new_id = redis.call('INCR', KEYS[1]) local dest = KEYS[1] .. new_id local data = cjson.decode(ARGV[1]) data.id = new_id for k, v in pairs(data) do redis.call('HSET', dest, k, v) end -- note: ZADD <key> <score> <member> redis.call('ZADD', KEYS[1] .. 'ts', data.ts, new_id)
  • 9. Analyzing/segmenting events We now have events, but want to (for example) count the number of events of different types in a time range, equivalent to: SELECT type, COUNT(*) FROM actions WHERE … GROUP BY type ● We can use Lua to scan over the items in the time range, counting them ● We can create additional ZSETs, one for each event type… ○ actions:login:ts, actions:logout:ts, … ○ Stores (<event_id>: <ts>) pairs, like actions:ts ○ Can use ZCOUNT to get a count without scanning*
  • 10. Analyzing/segmenting events (continued) ● Or if you needed to index events by user id ○ Add (<event_id>, <user_id>) member/score pairs to actions:user ○ Easy to get total count/user with ZCOUNT (ZCOUNT actions:user <user_id> <user_id>) ○ Can partially induce a secondary timestamp index over the same data; to fetch a specific time range for one user ■ Use ZRANGEBYSCORE and ZREVRANGEBYSCORE on actions:ts for start/end of id range for a pair of timestamps (assuming synchronized clocks, or using Redis 3.2- unreleased Lua side-effects propagation) ■ Either: ● Use ZRANGEBYSCORE on actions:user to scan ids and filter ● Use ZRANGEBYSCORE + ZREVRANGEBYSCORE + ZRANGE to bisect (speed optimization, requires left padding of members with zeros)
  • 11. Combining structures for success (revisited) ● If you know you never need to extract individual fields, and you know that your events are unique… ○ Use a single ZSET with (<encoded json event>: <ts>) pairs ● If you are planning on bucketing based on time slot, only need a list of items ○ Use LISTs keyed as actions:<time slice> ○ Just RPUSH <encoded json event> onto these LISTs ● Approximate counts? HyperLogLog ● If you plan your metrics, you can explicitly count them in real time ○ INCR, DECR, INCRBY, INCRBYFLOAT, HINCRBY, HINCRBYFLOAT, ZINCRBY, all very fast ○ Lua scripting can be a huge win here
  • 12. Combining structures for success (revisited) ● Redis doesn’t need to be 100% of this ○ If you only need counts over arbitrary time ranges, just action:ts or the action:login:ts and related sorted sets may be enough ○ Redis can be your counters/aggregate/sorted set storage, even if it’s not your event storage ● HASHes + ZSETs can solve just about anything, alternatives can offer: ○ Better performance ○ More convenient access to necessary data ○ Lower memory utilization
  • 13. Next steps Time series is a specific example of data modeling... ● My data modeling talk from Redisconf 2015 ○ Get an idea of the general process involved ● Specific examples: ○ For indexing/search: chapter 7 of RiA, my Redisconf 2012 talk ○ Other data modeling examples: the rest of RiA, my blog ○ Survey of data modeling examples: my Python with Redis talk from July 2012 ● Google will know more