SlideShare a Scribd company logo
How you can benefit from using 
by javier ramirez 
@supercoco9 
https://teowaki.com 
https://datawaki.com
I was 
Lois Lane 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
redis 
has 
super 
powers 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower I: 
super speed 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
redis-benchmark -r 1000000 -n 2000000 -t get,set,lpush,lpop,mset -P 16 -q 
On my laptop: 
SET: 513610 requests per second 
GET: 641436 requests per second 
LPUSH: 845665 requests per second 
LPOP: 783392 requests per second 
MSET (10 keys): 89988 requests per second 
On a small digital ocean server ($5/month) 
SET: 227816 requests per second 
GET: 228258 requests per second 
LPUSH: 251098 requests per second 
LPOP: 251572 requests per second 
MSET (10 keys): 43918 requests per second 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower II: 
it doesn't hide 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
http://redis.io 
open source, BSD licensed, advanced 
key-value store. 
It is often referred to as a 
data structure server since keys can contain 
strings, hashes, lists, sets, sorted sets and 
hyperloglogs. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
started in 2009 by Salvatore Sanfilippo @antirez 
112 contributors at 
https://github.com/antirez/redis 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
The Redis Manifesto 
1.A DSL for Abstract Data Types 
2.Memory storage is #1 
3.Fundamental data structures for a 
fundamental API 
4.Two levels of API 
5.Code is like a poem; it's not just something 
we write to reach some practical result 
6.We're against complexity 
7.We optimize for joy 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower III: 
Redis makes 
You think 
javier ramirez @supercoco9 https://teowaki.com 
https://datawaki.com
Redis data types 
Strings 
Hashes 
Lists 
Sets 
Sorted Sets 
HyperLogLogs 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
basic commands 
Setting/getting/deleting/expiring 
Increment/decrement 
Pushing/popping 
Checking membership, size... 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
much cooler commands 
Setting only if exists 
Blocking pop 
(Blocking) pop from one list, push to another 
Get/set string ranges (and bit operations) 
Set intersections/diffs (and store) 
Pub/sub 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
A chat in 6 lines of code 
r=Redis.new driver: :hiredis 
r.subscribe “chatrooms:42” do |on| 
on.message do |topic, msg| 
puts “#{topic}: #{msg}” 
end 
end 
r.publish “chatrooms:42”, “Hello codemotion” 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower IV: 
atomicity 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
single threaded, so no 
concurrency problems 
transactions and lua 
scripts to run multiple 
operations atomically 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower V: 
flexible data 
persistence 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
Redis keeps 
everything 
in memory 
all the time 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
Does that mean if 
the server goes 
down I will lose 
my data? 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
NO* 
*unless you didn't configure it properly 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower VI: 
data distribution 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
High Availability & scaling out 
One master, several read-only 
slaves 
Sharding, Twemproxy, 
Dynomite 
Redis cluster 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
what's being used for 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
twitter 
Every time line (800 tweets 
per user) is on redis 
5000 writes per second avg 
300K reads per second 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
twitter 
user id tweet id metadata 
user info from 
gizmoduck 
(memcached) 
write API (from browser or client app) 
rpushx to Redis 
tweet info from 
tweetypie 
(memcached + mysql) 
your twitter 
timeline 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com 
fanout (flockDB) 
one per follower
Crashlytics 
Activity tracking with Strings 
and Bit Operations 
Event tracking with Hashes 
Leaderboards with Sorted Sets 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
soundcloud 
Roshi implements a time-series event storage 
via a LWW-element-set CRDT with inline 
garbage collection. 
Roshi is a stateless, distributed layer on top of 
Redis and is implemented in Go. It is partition 
tolerant, highly available and eventually 
consistent. 
https://github.com/soundcloud/roshi 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
World Of Warcraft 
Blizzard is quite secretive about it 
Known to have at least 8 servers with 64Gb each to 
serve user avatars 
Known to have seen 1.000.000 users concurrently in 
the Asian version of the game 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
stack overflow 
Three level cache: 
local cache (no persistence) 
sessions, and pending view count updates 
site cache 
hot question id lists, user acceptance rates... 
global cache (separate Redis DB) 
Inboxes, API usage quotas... 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
tumblr 
started using Redis for notifications (over 7000/s) 
because MySQL would struggle. 
They liked it, so then they replaced memcached too 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
Booking.com 
2TB of data in server-side cookie sessions 
36 masters – 36 slaves in 2 datacenters 
Implemented new command to have versioned race-free 
hash entries 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
pinterest object graph 
per user 
Redis SortedSet, with timestamp as the score to 
store the users followed explicitly 
store the users followed implicitly 
store the user’s explicit followers 
store the user’s implicit followers 
store boards followed explicitly 
Redis set to store boards unfollowed explicitly 
per board 
Redis Hash to store a board’s explicit followers 
Redis Set to store a board’s explicit unfollowers 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
youporn 
Most data is found in hashes with ordered sets used to 
know what data to show. 
zInterStore on: videos:filters:released, 
Videos:filters:orientation:straight,Videos:filters:categorie 
s:{category_id}, Videos:ordering:rating 
Then perform a zRange to get the pages we want and 
get the list of video_ids back. 
Then start a pipeline and get all the videos from hashes. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
snapchat 
Redis cluster of 216 master and 216 slaves. 
Over 400MM messages per day. 
Running on Google App Engine. 
No need to have an operations team. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
github 
Git as a service internally. 
Redis is used for storing routing info 
matching user repositories to server names 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
hipchat 
Redis for caching. 
Information like which users are in which 
rooms, presence information, who is online... 
Redis to balance XMPP, so it doesn’t matter 
which XMPP server you connect to. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
when things go wrong 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
the instagram case 
moving from redis to 
cassandra: 75% savings on 
servers 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
pick the right superhero
the twilio case 
credit card hell 
lesson learnt: 
know what you are doing. 
Don't change config on the fly 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
stripe 
Master didn't have persistence, but slaves did. 
Master was stopped, slaves kept working. 
Master was re-started, asked the slaves to replicate the 
master database (it was empty) 
All the data in the cluster was lost. 
Luckily, this was only a test, but a scary one. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
take the time to master 
your super powers
everybody fails, sometimes 
Salvatore Sanfilippo 
lost his own blog* 
because he forgot 
to configure persistance 
* he recovered it in 30 minutes 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
superpower VII: 
it doesn't get scared of 
big numbers 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
you can go 
a long way 
before having 
scary numbers 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
how teowaki is using redis 
javier ramirez @supercoco9 https://teowaki.com 
https://datawaki.com
Abusing queues 
keep track of every activity in the system, even if you 
don't need them all right now: 
- every page view 
- every API request 
- every time a record is created/updated/deleted 
benefits: 
- highly decoupled system 
- easier to divide into services 
- you can add behaviour without changing your app 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
intermediate cache 
* As a very fast lightweight storage for analytics data before 
sending them to our google bigquery based solution 
* As a cache for attributes frequently looked up in join tables 
(names, nicknames, guids, delegated or included 
model names...) 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
Some of our uses of Lua 
Expiring attributes inside a Redis hash 
Inserting notifications into a list only if there are not 
pending notifications from the same user for the 
same scope 
Paginating a list by an attribute 
Manipulating JSON directly at the Redis layer 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
counters 
Atomic counters can be safely invoked concurrently 
from anywhere, so you can implement “like” 
features, global sequences or usage monitoring 
systems in highly concurrent applications for free. 
You can share your counters with any other internal 
application and still be sure they won't collide. 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
Temporary data 
Redis allows us to self expire keys after a time has 
passed. You can use this mechanism for a simple 
cache 
If you operate on a key with expiration time, you 
can change its value and still keep the expiration 
going. By combining a decrementing counter with 
an expiration time, implementing usage quotas is 
trivial 
Also, you can inspect which keys you have in your 
server efficiently using SCAN commands 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
bloom filters 
bloom filter: space-efficient probabilistic data 
structure that is used to test whether an element is 
a member of a set. False positive matches are 
possible, but false negatives are not. 
Redis bit operations make easy to implement bloom 
filters 
We are using bloom filters for checking uniqueness 
of user names and reserved words without going to 
postgresql 
javier ramirez @supercoco9 https://teowaki.com 
https://datawaki.com
nginx + lua + redis 
Multiple levels of cache by using Redis on the webserver/ 
middleware layer 
http://wiki.nginx.org/HttpRedis 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
summarizing 
* Redis is more powerful than it seems 
* Very fast, easy to use, simple, good documentation 
* In-memory data structures, distributed, shared and persisted 
* Good as data store, intermediate data store, cache or queue 
* Lots of use cases, both in huge and smaller systems 
You should probably use it a lot more 
javier ramirez @supercoco9 https://teowaki.com https://datawaki.com 
https://datawaki.com
Find related links at 
https://teowaki.com/teams/javier-community/link-categories/redis 
¡gracias! 
If you enjoyed this talk, please sign up for 
https://teowaki.com 
Don't forget to invite your friends too! 
Javier Ramírez 
@supercoco9

More Related Content

What's hot (6)

TDC2016POA | Trilha Ruby - Stack Level too Deep e Tail Call Optimization: É u...
TDC2016POA | Trilha Ruby - Stack Level too Deep e Tail Call Optimization: É u...TDC2016POA | Trilha Ruby - Stack Level too Deep e Tail Call Optimization: É u...
TDC2016POA | Trilha Ruby - Stack Level too Deep e Tail Call Optimization: É u...
 
255605131525+how to setting cned school server on ibm x3400 m2+2tbx2 red
255605131525+how to setting cned school server on ibm x3400 m2+2tbx2 red255605131525+how to setting cned school server on ibm x3400 m2+2tbx2 red
255605131525+how to setting cned school server on ibm x3400 m2+2tbx2 red
 
255605131531+how to setting cned school server on ibm x3400 m2+3tbx2 red
255605131531+how to setting cned school server on ibm x3400 m2+3tbx2 red255605131531+how to setting cned school server on ibm x3400 m2+3tbx2 red
255605131531+how to setting cned school server on ibm x3400 m2+3tbx2 red
 
Attacker Ghost Stories - ShmooCon 2014
Attacker Ghost Stories - ShmooCon 2014Attacker Ghost Stories - ShmooCon 2014
Attacker Ghost Stories - ShmooCon 2014
 
Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007
 
Os Treat
Os TreatOs Treat
Os Treat
 

Viewers also liked

Administración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startupAdministración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startup
Fernando Blat
 
Salesfusion pa webinar_040214
Salesfusion pa webinar_040214Salesfusion pa webinar_040214
Salesfusion pa webinar_040214
Salesfusion
 

Viewers also liked (12)

Administración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startupAdministración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startup
 
Sequel @ madrid-rb
Sequel @  madrid-rbSequel @  madrid-rb
Sequel @ madrid-rb
 
Webinar - The Death of Cold Calling 2013
Webinar - The Death of Cold Calling 2013Webinar - The Death of Cold Calling 2013
Webinar - The Death of Cold Calling 2013
 
Webinar - How Marketing Automation can sales fall in love with CRM
Webinar - How Marketing Automation can sales fall in love with CRMWebinar - How Marketing Automation can sales fall in love with CRM
Webinar - How Marketing Automation can sales fall in love with CRM
 
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
 
Fly Ops Int Brochure
Fly Ops Int BrochureFly Ops Int Brochure
Fly Ops Int Brochure
 
Salesfusion pa webinar_040214
Salesfusion pa webinar_040214Salesfusion pa webinar_040214
Salesfusion pa webinar_040214
 
Using Social media in b2b marketing
Using Social media in b2b marketingUsing Social media in b2b marketing
Using Social media in b2b marketing
 
Email Marketing Workshop
Email Marketing WorkshopEmail Marketing Workshop
Email Marketing Workshop
 
Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...
 
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA LondonBuilding Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
 
Highly available distributed databases, how they work, javier ramirez at teowaki
Highly available distributed databases, how they work, javier ramirez at teowakiHighly available distributed databases, how they work, javier ramirez at teowaki
Highly available distributed databases, how they work, javier ramirez at teowaki
 

Similar to How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion 2014

Redis深入浅出
Redis深入浅出Redis深入浅出
Redis深入浅出
ruoyi ruan
 
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
javier ramirez
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
Joseph Scott
 

Similar to How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion 2014 (20)

API Analytics with Redis and Bigquery. NoSQLmatters Cologne '14 edition. Javi...
API Analytics with Redis and Bigquery. NoSQLmatters Cologne '14 edition. Javi...API Analytics with Redis and Bigquery. NoSQLmatters Cologne '14 edition. Javi...
API Analytics with Redis and Bigquery. NoSQLmatters Cologne '14 edition. Javi...
 
api analytics redis bigquery. Lrug
api analytics redis bigquery. Lrugapi analytics redis bigquery. Lrug
api analytics redis bigquery. Lrug
 
Fun with ruby and redis, arrrrcamp edition, javier_ramirez, teowaki
Fun with ruby and redis, arrrrcamp edition, javier_ramirez, teowakiFun with ruby and redis, arrrrcamp edition, javier_ramirez, teowaki
Fun with ruby and redis, arrrrcamp edition, javier_ramirez, teowaki
 
API analytics with Redis and Google Bigquery. NoSQL matters edition
API analytics with Redis and Google Bigquery. NoSQL matters editionAPI analytics with Redis and Google Bigquery. NoSQL matters edition
API analytics with Redis and Google Bigquery. NoSQL matters edition
 
Por que deberias haberle pedido redis a los reyes magos
Por que deberias haberle pedido redis a los reyes magosPor que deberias haberle pedido redis a los reyes magos
Por que deberias haberle pedido redis a los reyes magos
 
Big Data Analytics with Google BigQuery. By Javier Ramirez. All your base Co...
Big Data Analytics with Google BigQuery.  By Javier Ramirez. All your base Co...Big Data Analytics with Google BigQuery.  By Javier Ramirez. All your base Co...
Big Data Analytics with Google BigQuery. By Javier Ramirez. All your base Co...
 
How we are using BigQuery and Apps Scripts at teowaki
How we are using BigQuery and Apps Scripts at teowakiHow we are using BigQuery and Apps Scripts at teowaki
How we are using BigQuery and Apps Scripts at teowaki
 
Big Data analytics with Nginx, Logstash, Redis, Google Bigquery and Neo4j, ja...
Big Data analytics with Nginx, Logstash, Redis, Google Bigquery and Neo4j, ja...Big Data analytics with Nginx, Logstash, Redis, Google Bigquery and Neo4j, ja...
Big Data analytics with Nginx, Logstash, Redis, Google Bigquery and Neo4j, ja...
 
Ex200
Ex200Ex200
Ex200
 
Redis深入浅出
Redis深入浅出Redis深入浅出
Redis深入浅出
 
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
Big Data Analytics with Google BigQuery. GDG Summit Spain 2014
 
Twitch Plays Pokémon: Twitch's Chat Architecture
Twitch Plays Pokémon: Twitch's Chat ArchitectureTwitch Plays Pokémon: Twitch's Chat Architecture
Twitch Plays Pokémon: Twitch's Chat Architecture
 
Ephemeral DevOps: Adventures in Managing Short-Lived Systems
Ephemeral DevOps: Adventures in Managing Short-Lived SystemsEphemeral DevOps: Adventures in Managing Short-Lived Systems
Ephemeral DevOps: Adventures in Managing Short-Lived Systems
 
Bea con anatomy-of-web-attack
Bea con anatomy-of-web-attackBea con anatomy-of-web-attack
Bea con anatomy-of-web-attack
 
Pentesting an unfriendly environment: bypassing (un)common defences and mate ...
Pentesting an unfriendly environment: bypassing (un)common defences and mate ...Pentesting an unfriendly environment: bypassing (un)common defences and mate ...
Pentesting an unfriendly environment: bypassing (un)common defences and mate ...
 
Updated 70-741 exam brain dumps questions by certs4sale
Updated 70-741 exam brain dumps questions by certs4saleUpdated 70-741 exam brain dumps questions by certs4sale
Updated 70-741 exam brain dumps questions by certs4sale
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive
 
MySQL Install for Replication - Real Life Tutorial
MySQL Install for Replication - Real Life TutorialMySQL Install for Replication - Real Life Tutorial
MySQL Install for Replication - Real Life Tutorial
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 

More from javier ramirez

More from javier ramirez (20)

¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfest¿Se puede vivir del open source? T3chfest
¿Se puede vivir del open source? T3chfest
 
QuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series databaseQuestDB: The building blocks of a fast open-source time-series database
QuestDB: The building blocks of a fast open-source time-series database
 
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
 
Deduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDBDeduplicating and analysing time-series data with Apache Beam and QuestDB
Deduplicating and analysing time-series data with Apache Beam and QuestDB
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
 
Your Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic DatabaseYour Timestamps Deserve Better than a Generic Database
Your Timestamps Deserve Better than a Generic Database
 
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
 
QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728
 
Processing and analysing streaming data with Python. Pycon Italy 2022
Processing and analysing streaming  data with Python. Pycon Italy 2022Processing and analysing streaming  data with Python. Pycon Italy 2022
Processing and analysing streaming data with Python. Pycon Italy 2022
 
QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...QuestDB: ingesting a million time series per second on a single instance. Big...
QuestDB: ingesting a million time series per second on a single instance. Big...
 
Servicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en AragónServicios e infraestructura de AWS y la próxima región en Aragón
Servicios e infraestructura de AWS y la próxima región en Aragón
 
Primeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessPrimeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverless
 
How AWS is reinventing the cloud
How AWS is reinventing the cloudHow AWS is reinventing the cloud
How AWS is reinventing the cloud
 
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAMAnalitica de datos en tiempo real con Apache Flink y Apache BEAM
Analitica de datos en tiempo real con Apache Flink y Apache BEAM
 
Getting started with streaming analytics
Getting started with streaming analyticsGetting started with streaming analytics
Getting started with streaming analytics
 
Getting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipelineGetting started with streaming analytics: Setting up a pipeline
Getting started with streaming analytics: Setting up a pipeline
 
Getting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep DiveGetting started with streaming analytics: Deep Dive
Getting started with streaming analytics: Deep Dive
 
Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)Getting started with streaming analytics: streaming basics (1 of 3)
Getting started with streaming analytics: streaming basics (1 of 3)
 
Monitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWSMonitorización de seguridad y detección de amenazas con AWS
Monitorización de seguridad y detección de amenazas con AWS
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 

How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion 2014

  • 1. How you can benefit from using by javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. I was Lois Lane javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 8. redis has super powers javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 9. superpower I: super speed javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 10. redis-benchmark -r 1000000 -n 2000000 -t get,set,lpush,lpop,mset -P 16 -q On my laptop: SET: 513610 requests per second GET: 641436 requests per second LPUSH: 845665 requests per second LPOP: 783392 requests per second MSET (10 keys): 89988 requests per second On a small digital ocean server ($5/month) SET: 227816 requests per second GET: 228258 requests per second LPUSH: 251098 requests per second LPOP: 251572 requests per second MSET (10 keys): 43918 requests per second javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 11. superpower II: it doesn't hide javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 12. http://redis.io open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets and hyperloglogs. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 13. started in 2009 by Salvatore Sanfilippo @antirez 112 contributors at https://github.com/antirez/redis javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 14. The Redis Manifesto 1.A DSL for Abstract Data Types 2.Memory storage is #1 3.Fundamental data structures for a fundamental API 4.Two levels of API 5.Code is like a poem; it's not just something we write to reach some practical result 6.We're against complexity 7.We optimize for joy javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 15. superpower III: Redis makes You think javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 16. Redis data types Strings Hashes Lists Sets Sorted Sets HyperLogLogs javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 17. basic commands Setting/getting/deleting/expiring Increment/decrement Pushing/popping Checking membership, size... javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 18. much cooler commands Setting only if exists Blocking pop (Blocking) pop from one list, push to another Get/set string ranges (and bit operations) Set intersections/diffs (and store) Pub/sub javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 19. A chat in 6 lines of code r=Redis.new driver: :hiredis r.subscribe “chatrooms:42” do |on| on.message do |topic, msg| puts “#{topic}: #{msg}” end end r.publish “chatrooms:42”, “Hello codemotion” javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 20. superpower IV: atomicity javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 21. single threaded, so no concurrency problems transactions and lua scripts to run multiple operations atomically javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 22. superpower V: flexible data persistence javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 23. Redis keeps everything in memory all the time javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 24. Does that mean if the server goes down I will lose my data? javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 25. NO* *unless you didn't configure it properly javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 26. superpower VI: data distribution javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 27. High Availability & scaling out One master, several read-only slaves Sharding, Twemproxy, Dynomite Redis cluster javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 28. what's being used for javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 29. twitter Every time line (800 tweets per user) is on redis 5000 writes per second avg 300K reads per second javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 30. twitter user id tweet id metadata user info from gizmoduck (memcached) write API (from browser or client app) rpushx to Redis tweet info from tweetypie (memcached + mysql) your twitter timeline javier ramirez @supercoco9 https://teowaki.com https://datawaki.com fanout (flockDB) one per follower
  • 31. Crashlytics Activity tracking with Strings and Bit Operations Event tracking with Hashes Leaderboards with Sorted Sets javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 32. soundcloud Roshi implements a time-series event storage via a LWW-element-set CRDT with inline garbage collection. Roshi is a stateless, distributed layer on top of Redis and is implemented in Go. It is partition tolerant, highly available and eventually consistent. https://github.com/soundcloud/roshi javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 33. World Of Warcraft Blizzard is quite secretive about it Known to have at least 8 servers with 64Gb each to serve user avatars Known to have seen 1.000.000 users concurrently in the Asian version of the game javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 34. stack overflow Three level cache: local cache (no persistence) sessions, and pending view count updates site cache hot question id lists, user acceptance rates... global cache (separate Redis DB) Inboxes, API usage quotas... javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 35. tumblr started using Redis for notifications (over 7000/s) because MySQL would struggle. They liked it, so then they replaced memcached too javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 36. Booking.com 2TB of data in server-side cookie sessions 36 masters – 36 slaves in 2 datacenters Implemented new command to have versioned race-free hash entries javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 37. pinterest object graph per user Redis SortedSet, with timestamp as the score to store the users followed explicitly store the users followed implicitly store the user’s explicit followers store the user’s implicit followers store boards followed explicitly Redis set to store boards unfollowed explicitly per board Redis Hash to store a board’s explicit followers Redis Set to store a board’s explicit unfollowers javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 38. youporn Most data is found in hashes with ordered sets used to know what data to show. zInterStore on: videos:filters:released, Videos:filters:orientation:straight,Videos:filters:categorie s:{category_id}, Videos:ordering:rating Then perform a zRange to get the pages we want and get the list of video_ids back. Then start a pipeline and get all the videos from hashes. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 39. snapchat Redis cluster of 216 master and 216 slaves. Over 400MM messages per day. Running on Google App Engine. No need to have an operations team. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 40. github Git as a service internally. Redis is used for storing routing info matching user repositories to server names javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 41. hipchat Redis for caching. Information like which users are in which rooms, presence information, who is online... Redis to balance XMPP, so it doesn’t matter which XMPP server you connect to. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 42. when things go wrong javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 43. the instagram case moving from redis to cassandra: 75% savings on servers javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 44. pick the right superhero
  • 45. the twilio case credit card hell lesson learnt: know what you are doing. Don't change config on the fly javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 46. stripe Master didn't have persistence, but slaves did. Master was stopped, slaves kept working. Master was re-started, asked the slaves to replicate the master database (it was empty) All the data in the cluster was lost. Luckily, this was only a test, but a scary one. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 47. take the time to master your super powers
  • 48. everybody fails, sometimes Salvatore Sanfilippo lost his own blog* because he forgot to configure persistance * he recovered it in 30 minutes javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 49. superpower VII: it doesn't get scared of big numbers javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 50. you can go a long way before having scary numbers javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 51. how teowaki is using redis javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 52.
  • 53.
  • 54.
  • 55.
  • 56. Abusing queues keep track of every activity in the system, even if you don't need them all right now: - every page view - every API request - every time a record is created/updated/deleted benefits: - highly decoupled system - easier to divide into services - you can add behaviour without changing your app javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 57. intermediate cache * As a very fast lightweight storage for analytics data before sending them to our google bigquery based solution * As a cache for attributes frequently looked up in join tables (names, nicknames, guids, delegated or included model names...) javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 58. Some of our uses of Lua Expiring attributes inside a Redis hash Inserting notifications into a list only if there are not pending notifications from the same user for the same scope Paginating a list by an attribute Manipulating JSON directly at the Redis layer javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 59. counters Atomic counters can be safely invoked concurrently from anywhere, so you can implement “like” features, global sequences or usage monitoring systems in highly concurrent applications for free. You can share your counters with any other internal application and still be sure they won't collide. javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 60. Temporary data Redis allows us to self expire keys after a time has passed. You can use this mechanism for a simple cache If you operate on a key with expiration time, you can change its value and still keep the expiration going. By combining a decrementing counter with an expiration time, implementing usage quotas is trivial Also, you can inspect which keys you have in your server efficiently using SCAN commands javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 61. bloom filters bloom filter: space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not. Redis bit operations make easy to implement bloom filters We are using bloom filters for checking uniqueness of user names and reserved words without going to postgresql javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 62. nginx + lua + redis Multiple levels of cache by using Redis on the webserver/ middleware layer http://wiki.nginx.org/HttpRedis javier ramirez @supercoco9 https://teowaki.com https://datawaki.com
  • 63. summarizing * Redis is more powerful than it seems * Very fast, easy to use, simple, good documentation * In-memory data structures, distributed, shared and persisted * Good as data store, intermediate data store, cache or queue * Lots of use cases, both in huge and smaller systems You should probably use it a lot more javier ramirez @supercoco9 https://teowaki.com https://datawaki.com https://datawaki.com
  • 64. Find related links at https://teowaki.com/teams/javier-community/link-categories/redis ¡gracias! If you enjoyed this talk, please sign up for https://teowaki.com Don't forget to invite your friends too! Javier Ramírez @supercoco9