Python and riak a perfect couple for building

32
PYTHON AND RIAK DB A PERFECT COUPLE FOR HUGE SCALE DISTRIBUTED COMPUTING twitter Github @Narenarya3 @narenaryan CORRECT WITH GRAMMARLY IGNORE

Transcript of Python and riak a perfect couple for building

Page 1: Python and riak   a perfect couple for building

PYTHON ANDRIAK DB

A PERFECT COUPLE FOR HUGESCALE DISTRIBUTED COMPUTING

twitter Github

@Narenarya3@narenaryan

CORRECT WITH GRAMMARLY IGNORE

Page 2: Python and riak   a perfect couple for building

WHAT RIAK CAN DO?Riak is a database that helps any business by supporting these

4 features

1. 100% uptime2. Infinite scale*3. Fault recovery4. Low latency

Page 3: Python and riak   a perfect couple for building

WHY CARE FAULTTOLERANCE?

Companies rely on data to power their day-todayoperations. Even minutes of application downtime canmean lost sales, a poor user experience, and a bruised

brand.This can add up to millions in lost revenue

Page 4: Python and riak   a perfect couple for building

NEVER LOSE ACUSTOMER IN THEBUSINESS DUE TO

LATENCY

Page 5: Python and riak   a perfect couple for building

WHAT EXACTLY RIAK IS?Different than traditional relational databases and other

“NoSQL” (non-relational) databases, Riak offers benefits ofenormous availability, replication and monitoring – all in a

highly distributed deployment

Built on Erlang for rock solid stabilityOpen source implementation of Dynamo paper byAmazon

Page 6: Python and riak   a perfect couple for building

NO 2:00AM EMERGENCYCALLS FOR AN ENGINEER

Page 7: Python and riak   a perfect couple for building

DISTRIBUTEDDATABASES

Data distrbution is achieved through two things.

ReplicationPartition

Page 8: Python and riak   a perfect couple for building

Replication

Page 9: Python and riak   a perfect couple for building

Partition

Page 10: Python and riak   a perfect couple for building

CAP THEOROMBrewer's CAP Theorom states that CAP loosely states thatyou can have a C (consistent), A (available), or P (partition-

tolerant) system, but you can only choose any 2 of them at aparticular time.

Consistency + Partition Toleranceor

Availability + Partition Tolerance

Page 11: Python and riak   a perfect couple for building

Riak’s solution is based on Amazon Dynamo’s novelapproach of a tunable AP system. Riak has a two knob

theory which sets both levels of availlability andconsistency.

RIAK'S TUNABLE CAPPARAMETERS

Level of AvailabilityLevel of Consistency

Page 12: Python and riak   a perfect couple for building

RIAK N-R-W STRATEGY1. N - No of nodes to replicate data

2. R - No of nodes to be read to confirm a successful read

3. W - No of nodes to write to confirm a successful write

Page 13: Python and riak   a perfect couple for building

N-R-W

Page 14: Python and riak   a perfect couple for building

RIAK'S CONSISTENTHASHING STRATEGY

Page 15: Python and riak   a perfect couple for building

OPERATIONALSIMPLICITY

# Add a node to existing cluster$ riak­admin cluster join [email protected]

# Remove a node from existing cluster$ riak­admin cluster leave NODE

# Replaces a failed node with new one in cluster$ riak­admin cluster replace NODE_1 NODE_2

# Shows the changes we made to cluster$ riak­admin cluster plan

# Only modifies cluster state after commiting$ riak­admin cluster replace NODE_1 NODE_2

#Check ring status$ riak­admin cluster status

Page 16: Python and riak   a perfect couple for building

DO YOU KNOW, RIAK ISBASE

Basically AvailableSoft-stateEventually consistentDurable

Page 17: Python and riak   a perfect couple for building

WHY PYTHON?

FUN | POWER | LOVE | ZILLIONREASONS

Page 18: Python and riak   a perfect couple for building

I LOVE PYTHONbecause of it's

1. Expressive power2. Simplicity3. Multi domain expertise4. Mammoth library base

more than that....

Page 19: Python and riak   a perfect couple for building

Python is in first three clients Riak 1.0 supported.

DOES RIAK HAS APYTHON CLIENT

Yes, Riak has six official clients for Major programminglanguages.

Page 20: Python and riak   a perfect couple for building

RIAK FOR IMPATIENTimport riak

client = riak.RiakClient()

bucket = client.bucket('developers')

person = bucket.new('python_developer_1', data={    'name': 'Naren',    'age': 22,    'company': 'Mr. Startup!',})

person.store()

Page 21: Python and riak   a perfect couple for building

4 SIMPLE METHODS TOSTART1. RiakClient2. bucket3. new4. store

Page 22: Python and riak   a perfect couple for building

BASIC PYTHON CLIENTMETHODS

RiakClient - creates a client connnection to Database

bucket - Creates a bucket if not exists, else uses it

new - creates a new key-value data pair

store - Stores key-value pair in database

Page 23: Python and riak   a perfect couple for building

TWO MORE METHODS TOCOMPLETE SIMPLICITY

get - Fetches a bucket data row using key

get_data - Fetches value associated for that key

Page 24: Python and riak   a perfect couple for building

SEE HOW CODE WORKSimport riak

client = riak.RiakClient()

bucket = client.bucket('developers')

naren = user_bucket.get('python_developer_1')

naren_dict = naren.get_data()

Page 25: Python and riak   a perfect couple for building

RIAK CLIENT VARIATIONSRiakClient()

RiakClient(protocol='http', host='127.0.0.1', http_port=8098)

RiakClient(nodes=[{'host':'127.0.0.1','http_port':8098}])

Nodes are the remote systems or virtual containers runningRiak Servers . When your data size is increasing grow your

data horizontally by allocating more nodes to cluster

Page 26: Python and riak   a perfect couple for building

RIAK SEARCHRiak Search 2.0 is an integration of Solr (for indexing and

querying) and Riak (for storage and distribution).It hassearch capability on distributed riak servers

results = client.fulltext_search('famous', 'name_s:Lion*')print resultsprint results['docs']

RIAK MAP REDUCE

Page 27: Python and riak   a perfect couple for building

ARCHITECTURE

Riak has a very good support for map-reducing of big data

Page 28: Python and riak   a perfect couple for building

WHAT WE ARE GAININGThe advantages of using Riak and Python are:

Fast and easy setupDeveloper friendly stackLess operational costHorizontal scaling on demandRock solid consistencyNow Flask and Django projects can scale on huge data

Page 29: Python and riak   a perfect couple for building

WHERE YOU SHOULDNOT USE RIAK?

You should not use Riak

If you have average sized data needs.If you are nostalgic about SQL and queries

IF YOU DON'T HAVE ANYPROBLEM NOW

Page 30: Python and riak   a perfect couple for building

WHERE YOU SHOULD USERIAK?