PYTHON AND
RIAK DB
A PERFECT COUPLE FOR HUGE
SCALE 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% uptime
2. Infinite scale*
3. Fault recovery
4. Low latency
WHY CARE FAULT
TOLERANCE?
Companies rely on data to power their day-today
operations. Even minutes of application downtime can
mean lost sales, a poor user experience, and a bruised
brand.This can add up to millions in lost revenue
NEVER LOSE A
CUSTOMER IN T
BUSINESS DUE T
LATENCY
WHAT EXACTLY RIAK IS?
Different than traditional relational databases and other
“NoSQL” (non-relational) databases, Riak offers benefits of
enormous availability, replication and monitoring – all in a
highly distributed deployment
Built on Erlang for rock solid stability
Open source implementation of Dynamo paper by
Amazon
NO 2:00AM EMERGENCY
CALLS FOR AN ENGINEER
DISTRIBUTED
DATABASES
Data distrbution is achieved through two things.
Replication
Partition
Replication
Partition
CAP THEOROM
Brewer's CAP Theorom states that CAP loosely states that
you can have a C (consistent), A (available), or P (partition-
tolerant) system, but you can only choose any 2 of them at a
particular time.
Consistency + Partition Tolerance
or
Availability + Partition Tolerance
Riak’s solution is based on Amazon Dynamo’s novel
approach of a tunable AP system. Riak has a two knob
theory which sets both levels of availlability and
consistency.
RIAK'S TUNABLE CAP
PARAMETERS
Level of Availability
Level of Consistency
RIAK N-R-W STRATEGY
1. 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 CONSISTENT
HASHING STRATEGY
OPERATIONAL
SIMPLICITY
# 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 IS
BASE
Basically Available
Soft-state
Eventually consistent
Durable
WHY PYTHON?
FUN | POWER | LOVE | ZILLION
REASONS
I LOVE PYTHON
because of it's
1. Expressive power
2. Simplicity
3. Multi domain expertise
4. Mammoth library base
more than that....
Python is in first three clients Riak 1.0 supported.
DOES RIAK HAS A
PYTHON CLIENT
Yes, Riak has six official clients for Major programming
languages.
RIAK FOR IMPATIENT
import 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 TO
START
1. RiakClient
2. bucket
3. new
4. store
BASIC PYTHON CLIENT
METHODS
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 TO
COMPLETE SIMPLICITY
get - Fetches a bucket data row using key
get_data - Fetches value associated for that key
SEE HOW CODE WORKS
import riak
client = riak.RiakClient()
bucket = client.bucket('developers')
naren = user_bucket.get('python_developer_1')
naren_dict = naren.get_data()
RIAK CLIENT VARIATIONS
RiakClient()
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 running
Riak Servers . When your data size is increasing grow your
data horizontally by allocating more nodes to cluster
RIAK SEARCH
Riak Search 2.0 is an integration of Solr (for indexing and
querying) and Riak (for storage and distribution).It has
search capability on distributed riak servers
results = client.fulltext_search('famous', 'name_s:Lion*')
print results
print results['docs']
RIAK MAP REDUCE
ARCHITECTURE
Riak has a very good support for map-reducing of big data
WHAT WE ARE GAINING
The advantages of using Riak and Python are:
Fast and easy setup
Developer friendly stack
Less operational cost
Horizontal scaling on demand
Rock solid consistency
Now Flask and Django projects can scale on huge data
WHERE YOU SHOULD
NOT 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 ANY
PROBLEM NOW
WHERE YOU SHOULD USE
RIAK?
MUCH MORE
Riak Book
Riak DB
Client libraries
Python and RiakDB
THANK YOU
NARENARYA@LIVE.COM
-
-
-
@Narenarya3
Source code for this slides
Website

Python and riak a perfect couple for building