why your mongodb needs redis

30
Why Your MongoDB Needs Redis Ask a Redis Expert™ Webinar September 3 rd , 2015

Upload: itamar-haber

Post on 16-Jan-2017

2.213 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Why Your MongoDB Needs Redis

Why Your MongoDBNeeds RedisAsk a Redis Expert™ Webinar

September 3rd, 2015

Page 2: Why Your MongoDB Needs Redis

@itamarhaber

A Redis Geek and Cheif Developer AdvocateatHave you signed for newsletter?[1] http://bit.ly/RedisWatch

Page 3: Why Your MongoDB Needs Redis

The Menu: What MongoDB? What Redis?

A document-oriented disk-based

database

If you’re here,you’re probably

already using it

An in-memory and optionally persistable data structuresengine

Redis isBlazing-Fast™

Page 4: Why Your MongoDB Needs Redis

Why broth?“Both projects are about there is something wrong if we use an RDBMS for all the kind of works… in response to the same non-nail problems, these two tools have taken different paths”

[2] MongoDB and Redis: a different interpretation of what's wrong with Relational DBs, June 3rd 2009, @

antirez

Page 5: Why Your MongoDB Needs Redis

● “… an [4] open source (BSD licensed), in-memorydata structure store, used as database, cache and message broker."

● 5 data structures, 180+ commands, in-memory, persistable to disk, atomic operations, Lua scripting, replication, high availibility, clustering and an active & vibrant community

● Nee circa 2009, by [5] antirez(a.k.a Salvatore Sanfilippo)

● Sponsored by Redis Labs

[3] Redis (REmote Dictionary Server)

Page 6: Why Your MongoDB Needs Redis

Why is Redis so Glazing Fast?Is not unlike asking “Why is a Ferrari so fast?”

Answer: Performance dictates the Design

Page 7: Why Your MongoDB Needs Redis

Redis is designed for performance• [6] The Redis Manifesto: We’re against complexity• RAM is fast (

[7] Latency Numbers Every Programmer Should Know)• C is fast ([8] Programming Languages Benchmark)• (mostly) single-threaded event loops are fast• Data structures are optimized for performance• Transparent complexity, time-space tradeoff knobs, …• Shameless Plug:

[9] webinar – How To Achieve 1.5 Million ops/second with Redis

Page 9: Why Your MongoDB Needs Redis

Hors d'oeuvre: La Quiche• You can make an excellent

quiche cache with Redis• Configurable eviction, key expiration and

optional data persistence <- blend and mix them to your taste

• Manage the cache in app; wrap the logic around your primary database driver; or grab something ready from GitHub

Page 10: Why Your MongoDB Needs Redis

Souped up Intelligent Cache

Intelligent cache “understands”

the data it manages,

whereas for the dumb ones data

is opaque

Page 11: Why Your MongoDB Needs Redis

[11] An introduction to Redis data types

A talk about Redis’ Data Types

Primary1. String2. Hash3. List4. Set 5. Zorted Set

Secondary1. Integer2. Float3. String bitmap4. HyperLogLog5. Coming: Geo hash,

Bloom filter

NOT!

Page 13: Why Your MongoDB Needs Redis

Entremets: Counting with RedisBefore moving to the main course, consider the common need for counting things. Arguably, any database can do that, but do you want to load yours with that?

Redis is great for counting stuff and does it reallyfast…

Page 14: Why Your MongoDB Needs Redis

- Main Course -Stop Big Data Indigestion

Before It Starts

Page 15: Why Your MongoDB Needs Redis

You probably haven't seen anything like this before

Volume

Velocity Variety

MongoDB truly excels when is comes to volume and variety of data……but data coming in at extreme velocity posesa digestive challenge forfor any disk-based database

Page 16: Why Your MongoDB Needs Redis

Data ingestion at high velocityMobile, online and IoT appsproduce more and more datawith every day that passes.

Simply storing the data as itcomes in doesn't cut it anymore – real time processing is a must in order distill information from the data as it rushes in.

Page 17: Why Your MongoDB Needs Redis

A talk about more performance

By doing LESSyou can do MORE(with MongoDB)

Put differently, "chew" your data with Redis to prevent data ingestion indigestion

Page 18: Why Your MongoDB Needs Redis

Use case A: Google Analytics• A real time analytics platform provider• Strongly focuses on users' behavior• Primary data storage is MongoDB• Activity is collected immediately or in bulks• Raw data fed to Hadoop for offline crunching• Real time metrics and initial information from

the stream is obtained with Redis

NOT!

Page 19: Why Your MongoDB Needs Redis

The tidal flow

Sessions events

Real time analysis

Offline analysis

Page 20: Why Your MongoDB Needs Redis

Deep dive topic: sessionizing data• Stream of events• A session is a document• Each has 10s-1000s events• Events from different users

arrive in order but interleaved• The result: many small updates

to each session's document• Peak load: 1.1M ops/sec (Q1 2015)

Page 21: Why Your MongoDB Needs Redis

You say potato, I say potatoHash data type:HSET session:1 event:1 dataHSET session:1 event:2 data ...

HINCRBY session:1 seq 1

JSON:{ session: 1, events: [ { id: 1, data: data }, { id: 2, data: data }, ...

Page 22: Why Your MongoDB Needs Redis

Swallowing in Pythonimport redisimport pymongo

r = redis.Redis()session = r.hgetall('session:1')# {'event:1': 'data', 'event:2': 'data', 'seq': '2'}...m = pymongo.MongoClient()db = m.rtasessionid = db.sessions.insert_one(session)

Page 23: Why Your MongoDB Needs Redis

Keeping track of sessions• Sessions end after a logout or a timeout• Logout events are trivial to detect• Timeouts, e.g. 30 minutes of inactivity, are

trickier to manage considering there could be 10,000s of active sessions

• This is where Redis' key expiry and keyspace notifications come in very handy

Page 24: Why Your MongoDB Needs Redis

Once you see it, it can't be unseenUsing Redis as a buffer in front of MongoDB for write-intensive, hot Big Data is a useful pattern that makes it easy to get information in real time as well as distribute the load more efficiently.

Ceci n’est pasune Quiche

Page 25: Why Your MongoDB Needs Redis

Use case B: Waze• An international navigation app/service• Strongly focuses on public transit• 10s of millions of users during peak hours• Primary data storage is MongoDB• Base data is created in advance• Real time updates (traffic, vehicles and

passengers) pour into Redis for scheduling adjustments and notifications

NOT!

Page 26: Why Your MongoDB Needs Redis

Use case C: Tinder• A dating app/service• Strongly focuses on spatially-related groups• Primary data storage is MongoDB• Data includes user profiles & preferences• An influx of positional and preferential

("swipes") events is first munched by Redis

NOT!

Page 27: Why Your MongoDB Needs Redis

Use case D: Clash of Clans• A massive real time game• Strongly focuses on matched team play• 1000s of teams with 100s of members• Primary data storage is MongoDB• Match progress is sieved through Redis for

real time resources status, leaderboards and scoring

NOT!

Page 28: Why Your MongoDB Needs Redis

Use case E: Weather.com• IoT startup• Focuses on environmental monitoring• Pilot: real time fire fighting• Primary data storage is MongoDB• Sensor data (temperature, humidity, …) is

aggregated in Redis, providing warnings and alarms in real time

NOT!

Page 29: Why Your MongoDB Needs Redis

Getting started with Redis• Try it online at [14] http://try.redis.io/• Build it from the source

• [15] Try Redis Labs Enterprise Cluster• Run it in a container

• [16] Connect to it from any language

git clone https://github.com/antirez/rediscd redisgit checkout 3.0.1make; make test; make install

docker run -d --name redis -p 6379:6379 redis

Page 30: Why Your MongoDB Needs Redis

Questions or feedback? Contact me!Itamar Haber

Chief Developer Advocate

📧 [email protected]@itamarhaber

Follow us on Twitter@redislabs