SlideShare a Scribd company logo
1 of 48
Download to read offline
javier ramirez
@supercoco9
How you can benefit
from using
Redis
I was
Lois Lane
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
redis
has
super
powers
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
myth: the bottleneck
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
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 and sorted sets.
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
started in 2009 by Salvatore Sanfilippo @antirez
109 contributors at
https://github.com/antirez/redis
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Redis makes
you think
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Redis data types
Strings
Hashes
Lists
Sets
Sorted Sets
HyperLogLog
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
basic commands
Setting/getting/deleting/expiring
Increment/decrement
Pushing/popping
Checking membership, size...
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
A chat in 6 lines of code
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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”
atomicity
single threaded, so no
concurrency problems
transactions and lua
scripts to run multiple
operations atomicallyjavier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Scripting with lua
You can use Lua for scripting Redis when you need to
atomically execute a sequence of commands in which
the output of a command is used as input for another
It reduces the need to use complex lock mechanisms
and simplifies dependencies between clients
You can even extend the functionality of Redis by using
Lua scripts
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Redis keeps
everything
in memory
all the time
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Persistance: RDB
Compact binary format
Saves snapshots every few minutes
Good for backups and synchronizing
If Redis crashes, a few minutes worth of
data will be lost
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Durability: AOF
Log text format
Configurable durability
Large file, can slow down startup
If Redis crashes, typically one second of
data could be lost
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
High Availability & scaling out
one master, several
read-only slaves
sharding
Twemproxy & redis cluster
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
what's being used for
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
twitter
user info from
gizmoduck
(memcached)
user id tweet id metadata
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 Codemotion 2014
fanout (flockDB)
one per follower
World Of Warcraft
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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
pinterest object graph
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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
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 Codemotion 2014
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 Codemotion 2014
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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.
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 Codemotion 2014
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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.
when things go wrong
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
the instagram case
moving from redis to
cassandra: 75% savings on
servers
lesson learnt:
know when redis is not appropriate
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
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 Codemotion 2014
Numbers can be scary
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
Twitter: 2TB RAM for Redis on its own servers
Blizzard: At least 8 servers with 64Gb each
Pinterest: 110 Redis instances
Instagram: 1.2 TB of data
you can go
a long way
before having
scary numbers
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
how teowaki is using redis
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
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 Codemotion 2014
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 Codemotion 2014
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 Codemotion 2014
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 Codemotion 2014
nginx + lua + redis
apache + mruby + redis
Multiple levels of cache by using Redis on the webserver/
middleware layer
http://wiki.nginx.org/HttpRedis
javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
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 Codemotion 2014
Find related links at
https://teowaki.com/teams/javier-community/link-categories/redis
Grazie.
If you enjoyed this talk, please sign up for
https://teowaki.com
Javier Ramírez
@supercoco9
Codemotion 2014

More Related Content

More from javier ramirez

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 ...javier ramirez
 
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 QuestDBjavier ramirez
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)javier ramirez
 
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 Databasejavier ramirez
 
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 ...javier ramirez
 
QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728QuestDB-Community-Call-20220728
QuestDB-Community-Call-20220728javier ramirez
 
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 2022javier ramirez
 
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...javier ramirez
 
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ónjavier ramirez
 
Primeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessPrimeros pasos en desarrollo serverless
Primeros pasos en desarrollo serverlessjavier ramirez
 
How AWS is reinventing the cloud
How AWS is reinventing the cloudHow AWS is reinventing the cloud
How AWS is reinventing the cloudjavier ramirez
 
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 BEAMjavier ramirez
 
Getting started with streaming analytics
Getting started with streaming analyticsGetting started with streaming analytics
Getting started with streaming analyticsjavier ramirez
 
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 pipelinejavier ramirez
 
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 Divejavier ramirez
 
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)javier ramirez
 
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 AWSjavier ramirez
 
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...javier ramirez
 
Recomendaciones, predicciones y detección de fraude usando servicios de intel...
Recomendaciones, predicciones y detección de fraude usando servicios de intel...Recomendaciones, predicciones y detección de fraude usando servicios de intel...
Recomendaciones, predicciones y detección de fraude usando servicios de intel...javier ramirez
 
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...javier ramirez
 

More from javier ramirez (20)

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
 
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...
Consulta cualquier fuente de datos usando SQL con Amazon Athena y sus consult...
 
Recomendaciones, predicciones y detección de fraude usando servicios de intel...
Recomendaciones, predicciones y detección de fraude usando servicios de intel...Recomendaciones, predicciones y detección de fraude usando servicios de intel...
Recomendaciones, predicciones y detección de fraude usando servicios de intel...
 
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...
Open Distro for ElasticSearch and how Grimoire is using it. Madrid DevOps Oct...
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

how you can benefit from using redis. Codemotion Roma Edition

  • 1. javier ramirez @supercoco9 How you can benefit from using Redis
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. I was Lois Lane javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 8. redis has super powers javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 9. myth: the bottleneck javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 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 Codemotion 2014
  • 11. 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 and sorted sets. javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 12. started in 2009 by Salvatore Sanfilippo @antirez 109 contributors at https://github.com/antirez/redis javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 13. Redis makes you think javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 14. Redis data types Strings Hashes Lists Sets Sorted Sets HyperLogLog javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 15. basic commands Setting/getting/deleting/expiring Increment/decrement Pushing/popping Checking membership, size... javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 16. 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 Codemotion 2014
  • 17. A chat in 6 lines of code javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 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”
  • 18. atomicity single threaded, so no concurrency problems transactions and lua scripts to run multiple operations atomicallyjavier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 19. Scripting with lua You can use Lua for scripting Redis when you need to atomically execute a sequence of commands in which the output of a command is used as input for another It reduces the need to use complex lock mechanisms and simplifies dependencies between clients You can even extend the functionality of Redis by using Lua scripts javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 20. Redis keeps everything in memory all the time javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 21. Persistance: RDB Compact binary format Saves snapshots every few minutes Good for backups and synchronizing If Redis crashes, a few minutes worth of data will be lost javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 22. Durability: AOF Log text format Configurable durability Large file, can slow down startup If Redis crashes, typically one second of data could be lost javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 23. High Availability & scaling out one master, several read-only slaves sharding Twemproxy & redis cluster javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 24. what's being used for javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 25. 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 Codemotion 2014
  • 26. twitter user info from gizmoduck (memcached) user id tweet id metadata 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 Codemotion 2014 fanout (flockDB) one per follower
  • 27. World Of Warcraft javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 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
  • 28. pinterest object graph javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 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
  • 29. 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 Codemotion 2014
  • 30. 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 Codemotion 2014
  • 31. javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 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.
  • 32. 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 Codemotion 2014
  • 33. javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 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.
  • 34. when things go wrong javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 35. the instagram case moving from redis to cassandra: 75% savings on servers lesson learnt: know when redis is not appropriate javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 36. 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 Codemotion 2014
  • 37. 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 Codemotion 2014
  • 38. Numbers can be scary javier ramirez @supercoco9 https://teowaki.com Codemotion 2014 Twitter: 2TB RAM for Redis on its own servers Blizzard: At least 8 servers with 64Gb each Pinterest: 110 Redis instances Instagram: 1.2 TB of data
  • 39. you can go a long way before having scary numbers javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 40. how teowaki is using redis javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 41. 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 Codemotion 2014
  • 42. 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 Codemotion 2014
  • 43. 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 Codemotion 2014
  • 44. 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 Codemotion 2014
  • 45. 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 Codemotion 2014
  • 46. nginx + lua + redis apache + mruby + redis Multiple levels of cache by using Redis on the webserver/ middleware layer http://wiki.nginx.org/HttpRedis javier ramirez @supercoco9 https://teowaki.com Codemotion 2014
  • 47. 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 Codemotion 2014
  • 48. Find related links at https://teowaki.com/teams/javier-community/link-categories/redis Grazie. If you enjoyed this talk, please sign up for https://teowaki.com Javier Ramírez @supercoco9 Codemotion 2014