This presentation shows Movile/Wavy uses cases, presented at RedisConf18 in San Francisco California. Here you can see how versatile is Redis how you can use it to leverage your business!
Unleash Your Potential - Namagunga Girls Coding Club
[Redis conf18] The Versatility of Redis
1. The Versatility of Redis
Powering our critical business using Redis
Luciano Sabença
Eiti Kimura
2. ABOUT US
● Software Engineer at Movile/Wavy
● Developer and architect of distributed systems
● Main interest areas are: Computer Theory, Machine
Learning and Distributed System.
● BS degree with praise in Computer Science by
University of Campinas.
Luciano Sabença
lucianosabenca
3. ABOUT US
● IT Coordinator and Software Architect at Movile
● Msc. in Electrical Engineering
● Apache Cassandra MVP (2014/2015 and 2015/2016)
● Apache Cassandra Contributor (2015)
● Cassandra Summit Speaker (2014 and 2015)
● Strata Hadoop World Singapore Speaker (2016)
● Spark Summit Speaker (2017)
Eiti Kimura
eitikimura
4. Movile is the company behind several
apps that makes the life easier
WE MAKE LIFE BETTER
THROUGH OUR APPS
7. BALANCE INFORMATION
Account: X3254
Balance: $1,564.20
100852
A deposit of $95.00 was
made to your account on
April 23th at 7:59pm.
Your balance is:
$1,659.20. Text STOP to
cancel or HELP for more
information.
9. PLAYKIDS
685-63
You have opted to
subscribe for Play Kids
access fo $14,99/mo.
Reply YES to confirm. Text
STOP to cancel or HELP for
more info.
10. PLAYKIDS
685-63
You have opted to
subscribe for Play Kids
access fo $14,99/mo.
Reply YES to confirm. Text
STOP to cancel or HELP for
more info.
YES
You successfully
subscribed to PK.
Download the app:
http://bit.ly/pp and enter
this validation code:
528-985-963 to access.
11.
12. AGENDA
● What/Why Redis?
● 1st Using Redis as Database
● 2nd Traditional Cache Usage
● 3rd A Distributed Lock case
● Lessons Learned / Pros & Cons
13. WHAT IS REDIS ?
● Redis is what is called a key-value store often
referred to as a NoSQL database
● It can handle concurrency problems very well
● Records can be set to expire after sometime
● It can be used in several different applications
14. WHY REDIS ?
● Most Redis Operations are atomic!
○ No need for external synchronization!
● Redis Async Replication is fast and makes Redis
reliable!
● All dataset is in memory: fast access!
● Data persistence: Durability!
16. 1st Use Case Intro
Exploring the Redis feature as a datastore we are using
in this case as a distributed database for our blacklist
datalayer service.
60 million phone
numbers
> 1 billion
requests/mo
latency < 5ms
17. Blacklist Usage by Our Services
Messaging Platform
BLACKLIST DATABASE LAYER
check
PLAY KIDS
685-63
18. Blacklist Usage by Our Services
Messaging Platform
BLACKLIST DATABASE LAYER
check
PLAY KIDS
You have opted to
subscribe for Play
Kids access fo
$14,99/mo. Reply YES
to confirm.
685-63
19. Blacklist Usage by Our Services
Billing Platform
BLACKLIST DATABASE LAYER
check
YES
685-63
PLAY KIDS
You have opted to
subscribe for Play
Kids access fo
$14,99/mo. Reply YES
to confirm.
20. Blacklist Usage by Our Services
Subscription Platform
BLACKLIST DATABASE LAYER
check
YES
You successfully
subscribed to PK.
Enter this validation
code: 528-985-963
685-63
PLAY KIDS
You have opted to
subscribe for Play
Kids access fo
$14,99/mo. Reply YES
to confirm.
21. Blacklist Usage by Our Services
Subscription Platform Billing Platform Messaging Platform
BLACKLIST DATABASE LAYER
check check check
685-63
YES
You successfully
subscribed to PK.
Enter this validation
code: 528-985-963
685-63
PLAY KIDS
You have opted to
subscribe for Play
Kids access fo
$14,99/mo. Reply YES
to confirm.
22. Blacklist Usage by Our Services
Web Pages Marketplaces
Broadcast
Applications
Third-Party
Applications
Mobile Apps
23. Blacklist Usage by Our Services
Subscription Platform Billing Platform Messaging Platform
BLACKLIST DATABASE LAYER
Web Pages Marketplaces
Broadcast
Applications
Third-Party
Applications
Mobile Apps
charge
subscribe
subscribe
charge
send SMS
send message
broadcast
check check check
APPLICATION LAYER
SERVICE LAYER
26. Old Architecture - Failure
● Large amount of memory
being used (~5GB/instance)
● High frequency of GC pauses
● General low performance
noticed
● No more memory available
(scale up limitation)
31. Results
● We saved more than 100 GB of memory
● Saved thousands Dollars in memory
● Distributed Data reliability
High message throughput
High scalability
Low costs
Low latency and
business impact
33. 2nd Use Case Intro
One of the most common Redis usages is as a cache.
A well known case to use in our solution to provide fast
access to our high performance services.
> 160 million
records
essential for the
high throughput of
our platforms
direct impact in
company's
revenue
34. By the way what is a Grey list concept?
We create a score to our users based on the product it
is subscribed, it intent to classify the user as a good
customer.
Phone Number: + 55 19 0000 1111 Score: 0,8
Phone Number: + 55 19 2323 0101 Score: 0,2
Phone Number: + 55 19 0202 0000 Score: 0,4
Phone Number: + 55 19 4242 9090 Score: 0,1
GREYLIST DATA LAYER
35. By the way what is a Greylist concept?
Would you like to
receive Sports News
for your location
$2,99/week. Reply
YES to confirm.
685-63
Media Partner
36. By the way what is a Greylist concept?
Would you like to
receive Sports News
for your location
$2,99/week. Reply
YES to confirm.
YES
685-63
Subscription Platform
Greylist Service Layer
37. By the way what is a Greylist concept?
Would you like to
receive Sports News
for your location
$2,99/week. Reply
YES to confirm.
YES
685-63
Subscription Platform
Greylist Service Layer
SORRY service
unavailable for your
phone number.
Congratulations now
you are subscribed to
receive Sports News
for your location. Text
STOP to cancel.
YES
SCORE > 0,5NO
38. By the way what is a Greylist concept?
Would you like to
receive Sports News
for your location
$2,99/week. Reply
YES to confirm.
YES
SORRY service
unavailable for your
phone number.
685-63
Greylist Service Layer
SORRY service
unavailable for your
phone number.
Congratulations now
you are subscribed to
receive Sports News
for your location. Text
STOP to cancel.
YES
SCORE > 0,5NO
39. By the way what is a Greylist concept?
Would you like to
receive Sports News
for your location
$2,99/week. Reply
YES to confirm.
YES
SORRY service
unavailable for your
phone number.
685-63
Subscription Platform
Greylist Service Layer
SORRY service
unavailable for your
phone number.
Media Partner
Congratulations now
you are subscribed to
receive Sports News
for your location. Text
STOP to cancel.
YES
NO SCORE > 0,5
41. Redis In the Solution
● We disabled Redis persistence and reached write rate over
300k/second.
● Peak of 400k writes/second
● Redis response is below ms.
● We have no impact in our subscription flow
42. Results
● Blocked more than 1MM subscriptions from bad
payers users.
● Saved around U$60k in media in a few months.
● Block Rate > 40% for some campaigns.
44. 3rd Use Case Intro
Exploring Redis as an orchestrator for our distributed
systems managing SMPP connections
Stateful
connection with
limited number of
binds
A connection can
be consumed by
more than one
instance
We should be
capable of load
balancing the
connections
50. Set The Lock:
SET resource_lock_name some_random_value NX PX <expiration>
How to set/release the Lock?
51. Set The Lock:
SET resource_lock_name some_random_value NX PX <expiration>
Release The Lock:
if redis.call("get",KEYS[1]) == ARGV[1] then
return redis.call("del",KEYS[1])
else
return 0
end
Source and More Information: https://redis.io/topics/distlock
How to set/release the Lock?
55. 1st Use case Lessons Learned
● Lack of multi DC support:
○ We replicate all writes which might cause
consistency problems
Application
DATACENTER 1 DATACENTER 2
56. 2nd Use case Lessons Learned
● Persistence Might Slow Down Redis
Main Memory Access Send 2KB Over Commodity
Network
Read Sequentially 1MB from
SSD
100 ns 900 ns 400 µs
Source: https://people.eecs.berkeley.edu/~rcs/research/interactive_latency.html
Date reference 2010-2012
57. Architecture Setup Mistake (do not do this)
Master
KeepAliveD
Slave
KeepAliveD
Virtual IP
Platform
Instance
writes
58. Master Failure Expected Scenario
Down
KeepAliveD
Slave
KeepAliveD
Virtual IP
Platform
Instance
writes
Master
KeepAliveD
Slave
KeepAliveD
Virtual IP
Platform
Instance
writes
60. What really happened
Master
KeepAliveD
Slave
KeepAliveD
Virtual IP
Platform
Instance
writes
● The old master goes up
assuming as master and
synchronizing old
information
● We lost a huge amount data
● Causing overall
consistencies problems
Lesson Learned: Don't try to use
home-made solutions. Use Redis
Sentinel instead.
61. 3rd Use case Lessons Learned
● Single point of failure
Platform
Platform
Platform
62. 3rd Use case Lessons Learned
● Single point of failure
Platform
Platform
Platform
Delay
Slave
Solutions for These Problems: Use a more complex lock algorithm (e.g. RedLock)
● Not very suitable for high throughput locks
Platform
Platform
Platform