python and riak a perfect couple for building

Post on 21-Jan-2017

336 Views

Category:

Data & Analytics

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PYTHON ANDRIAK DB

A PERFECT COUPLE FOR HUGESCALE DISTRIBUTED COMPUTING

twitter Github

@Narenarya3@narenaryan

CORRECT WITH GRAMMARLY IGNORE

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

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

NEVER LOSE ACUSTOMER IN THEBUSINESS DUE TO

LATENCY

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

NO 2:00AM EMERGENCYCALLS FOR AN ENGINEER

DISTRIBUTEDDATABASES

Data distrbution is achieved through two things.

ReplicationPartition

Replication

Partition

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

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

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

N-R-W

RIAK'S CONSISTENTHASHING STRATEGY

OPERATIONALSIMPLICITY

# Add a node to existing cluster$ riak­admin cluster join riak@127.0.0.1

# 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

DO YOU KNOW, RIAK ISBASE

Basically AvailableSoft-stateEventually consistentDurable

WHY PYTHON?

FUN | POWER | LOVE | ZILLIONREASONS

I LOVE PYTHONbecause of it's

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

more than that....

Python is in first three clients Riak 1.0 supported.

DOES RIAK HAS APYTHON CLIENT

Yes, Riak has six official clients for Major programminglanguages.

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()

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

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

TWO MORE METHODS TOCOMPLETE SIMPLICITY

get - Fetches a bucket data row using key

get_data - Fetches value associated for that key

SEE HOW CODE WORKSimport riak

client = riak.RiakClient()

bucket = client.bucket('developers')

naren = user_bucket.get('python_developer_1')

naren_dict = naren.get_data()

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

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

ARCHITECTURE

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

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

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

WHERE YOU SHOULD USERIAK?

THANK YOUNARENARYA@LIVE.COM- - -

@Narenarya3Source code for this slidesWebsite

top related