SlideShare a Scribd company logo
Building
Distributed Systems
decision guide
Oleksiy Kurnenkov
Core Infrastructure
Domain lead
OnApp
Building
Distributed Systems
decision guide
Introduction
Part I
Distributed system
is a set of interconnected functional units with separate
runtime context
MONOLITH : DISTRIBUTED
1 Runtime context
Coroutines
Threads
Process
N Runtime contexts
Nodes
Components
Clusters
Grids
SCALE
Small ->
Middle ->
Global ->
OS, LAN
LAN
WAN
TYPES
CDN
Grids
Clouds
Clusters
Enterprise
CDN
Grid
Globus Toolkit 6
BOINC
x-Torrent
Cloud
Cluster
Enterprise
TASKS
MMOG
Analysis
Sensors
Real Time Enterprise
Media
Storage
Computation
Transactions
Challenges
Availability
Scalability
Security
Openness
Heterogeneity
Concurrency
Transparency
Feasibility
It IS there
99.9999999%
Availability
It grows and shrinks
Scalability
U ain’ gonna crack it
>:|
Security
It is open for development
and integration
Opennes
Everything changes
Heterogeneity
Parallel workloads
Concurrency
Less know - less depend
Transparency
Simplify as possible
Feasibility
Fallacies
The network is reliable
Latency is zero
Bandwidth is infinite
The network is secure
Topology doesn't change
There is one administrator
Transport cost is zero
The network is homogeneous
Mechanics
Part II
Mechanics
I
Membership
Concurrency / Parallelism
Synchronization
Coordination
Consensus
Clustering
Who’s there?
Membership
Membership
Heartbeats
Up-2-date list of nodes
We are Legion
Concurrency / Parallelism
Concurrency / Parallelism
Actors
Process Calculi
Shared memory
MY precious!
Synchronization
Synchronisation
Mutex | Semaphore
Distributed Lock
Roger that!
Coordination
Coordination
Leader election
Orchestration
the ‘Two Generals Problem’
Deal
Consensus
Consensus
Quorum
Consistency Availability Partition tolerance
Altogether
Clustering
Clustering
Load Balancing
Redundancy
Availability
Replication
Partition tolerance
Mechanics
II
Scaling
Fault Detection
Failover
Recover
Fail back
Scaling
Vertical
Horisontal
Automatic
Fault Detection
Monitoring
Supervision
Activity Analysis
Failover
Data | State Accessibility
Resource allocation
Spare Capacity
Business Continuity
Recovery
State Reconstruction
Data backup
State dump
Failback
Data consistency
Conflict resolution
Apache YARN
Apache Zookeeper
Apache Mesos
Apache Drill
Google Chubby
CoreOS
Google Kubernetes
Google Dremel
Architecture
Part III
Client - Server
N-tier
Service oriented Architecture
Event Driven Architecture
P2P
Context
Building Distributed Systems
System Allocation
Architectural
entities
decomposition
Subsystem
Service
Component
Process
Object
Middleware
Fractal
Building Distributed Systems
Subsystem -> Component -> Process -> Object
Subsystem -> Component -> Process -> Object
Subsystem -> Component -> Process -> Object
Communication
Infrastructure
aka Middleware
IPC
-----------------------------
Remote Invocation
Group Communication
Messaging
IPC
Share data
Send data
Remote Invocation
Request - Reply
RPC
RMI
Group Communication
{ Uni | Multi | Broad } cast
Publish | Subscribe
Messaging
Message Queue
Message Broker
Pipe | Filter | Translator
Implementation
Part IV
Microcosm ->
Macrocosm
Middleware
[ * ] Process
Host
Network
Within a process
Threads
Shared memory
Mutex | Monitor
require 'thread'
class RaceCondition
def initialize(resource, concurrency_level)
@resource = resource
@concurrency_level = concurrency_level
end
def perform
@concurrency_level.times do
threads << Thread.new { action }
end
threads.each(&:join)
end
private
def threads
@threads ||= []
end
def action
@resource += 1
puts @resource
end
end
RaceCondition.new(0, 10).perform
# 12
# 3
# 5
# 6
# 7
# 8
# 910
# 4
require 'thread'
class Sycnhronizer
def initialize(resource, concurrency_level)
@resource = resource
@concurrency_level = concurrency_level
end
def perform
@concurrency_level.times do
threads << Thread.new { action }
end
threads.each(&:join)
end
private
def threads
@threads ||= []
end
def action
lock.synchronize do
@resource += 1
puts @resource
end
end
def lock
@lock ||= Mutex.new
end
end
Sycnhronizer.new(0, 10).perform
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9
# 10
Microcosm ->
Macrocosm
Process
[ * ] Host
NetworkMiddleware
Within a host
Processes
MQ | Shared memory | Pipes | UNIX Socket
Semaphore
# http://bogomips.org/ruby_posix_mq/
require 'posix_mq'
class Producer
attr_reader :mq
def initialize(mq_name)
@mq = POSIX_MQ.new("/foo", :rw)
end
def send(message, prio = 0)
puts "Send: #{message}. Priority #{prio}"
mq.send("#{message} #{prio}", prio)
end
end
p = Producer.new("/test_ipc")
p.send("Hello from #{Process.pid}", 10)
p.send("Hello from #{Process.pid}", 2)
p.send("Hello from #{Process.pid}", 0)
p.send("Hello from #{Process.pid}", 1)
p.send("Hello from #{Process.pid}", 20)
# ruby posix_mq/producer.rb
#
# Send: Hello from 12635. Priority 10
# Send: Hello from 12635. Priority 2
# Send: Hello from 12635. Priority 0
# Send: Hello from 12635. Priority 1
# Send: Hello from 12635. Priority 20
# http://bogomips.org/ruby_posix_mq/
require 'posix_mq'
class Consumer
attr_reader :mq
def initialize(mq_name)
@mq = POSIX_MQ.new("/foo", :rw)
end
def receive
mq.receive.first
end
def receive_non_block
mq.nonblock = true
begin
receive
rescue Errno::EAGAIN
mq.nonblock = false
puts "Nothing"
end
end
def shift
mq.tryshift
end
end
c = Consumer.new("/test_ipc")
while m = c.shift
puts "got: #{m}"
end
# ruby posix_mq/consumer.rb
# got: Hello from 12635 10
# got: Hello from 12635 20
# got: Hello from 12635 2
# got: Hello from 12635 1
# got: Hello from 12635 0
# https://github.com/pmahoney/process_shared
require 'process_shared'
mutex = ProcessShared::Mutex.new
mem = ProcessShared::SharedMemory.new(:int)
mem.put_int(0, 0)
pid1 = fork do
puts "in process 1 (#{Process.pid})"
10.times do
sleep 0.01
mutex.synchronize do
value = mem.get_int(0)
sleep 0.01
puts "process 1 (#{Process.pid}) incrementing"
mem.put_int(0, value + 1)
end
end
end
pid2 = fork do
puts "in process 2 (#{Process.pid})"
10.times do
sleep 0.01
mutex.synchronize do
value = mem.get_int(0)
sleep 0.01
puts "process 2 (#{Process.pid}) decrementing"
mem.put_int(0, value - 1)
end
end
end
Process.wait(pid1)
Process.wait(pid2)
# ruby shm.rb
#
# in process 1 (8038)
# in process 2 (8041)
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# process 1 (8038) incrementing
# process 2 (8041) decrementing
# value should be zero: 0
rd_child, wr_parent = IO.pipe
rd_parent, wr_child = IO.pipe
pid = fork do
rd_parent.close
wr_parent.close
wr_child.puts "sent from child process"
puts rd_child.gets
end
rd_child.close
wr_child.close
wr_parent.write "sent from parent process"
puts rd_parent.gets
# ruby pipes/pipes.rb
#
# sent from child process
# sent from parent process
require 'eventmachine'
module UnixServer
def receive_data(data)
puts data
EM.stop if data.chomp == "exit"
send_data("Server #{Process.pid}: Got #{data.chomp} from you")
close_connection_after_writing
end
end
EM.run do
puts "Started UNIX socket server on /tmp/sock"
EM::start_unix_domain_server("/tmp/sock", UnixServer)
end
# ruby server.rb
#
# Started UNIX socket server on /tmp/sock
#
# HELLO! My pid is 13847
require 'socket'
UNIXSocket.open("/tmp/sock") do |c|
c.write("HELLO! My pid is #{Process.pid}")
puts c.read
end
# ruby client.rb
#
# Server 13843: Got HELLO! My pid is 13847 from you
Microcosm ->
Macrocosm
Process
Host
[ * ] NetworkMiddleware
Over the Network
{ TCP | UDP } Socket
HTTP Client - Server
Async messaging
require "bunny"
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue("hello")
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}"
# cancel the consumer to exit
delivery_info.consumer.cancel
end
require "bunny"
conn = Bunny.new(:hostname => "rabbit.local")
conn.start
ch = conn.create_channel
q = ch.queue("hello")
ch.default_exchange.publish("Hello World!", :routing_key => q.name)
puts " [x] Sent 'Hello World!'"
conn.close
require "bunny"
conn = Bunny.new
conn.start
ch = conn.create_channel
x = ch.fanout("logs")
msg = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
x.publish(msg)
puts " [x] Sent #{msg}"
conn.close
require "bunny"
conn = Bunny.new
conn.start
ch = conn.create_channel
x = ch.fanout("logs")
q = ch.queue("", :exclusive => true)
q.bind(x)
puts " [*] Waiting for logs. To exit press CTRL+C"
begin
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] #{body}"
end
rescue Interrupt => _
ch.close
conn.close
end
Building Distributed Systems
Apache Kafka
RabbitMQ
Next time
To be continued:
Algorithms, patterns,
code!
Thank you!
Q&A

More Related Content

PDF
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
PDF
SDNDS.TW Mininet
PDF
GopherFest 2017 - Adding Context to NATS
PDF
OpenStack networking
PDF
Basic onos-tutorial
PDF
debugging openstack neutron /w openvswitch
PDF
Openstack Networking Internals - first part
PDF
SDN and Mininet: Some Basic Concepts
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
SDNDS.TW Mininet
GopherFest 2017 - Adding Context to NATS
OpenStack networking
Basic onos-tutorial
debugging openstack neutron /w openvswitch
Openstack Networking Internals - first part
SDN and Mininet: Some Basic Concepts

What's hot (20)

DOCX
SDN Training - Open daylight installation + example with mininet
PDF
cpu-affinity
PDF
Python twisted
PDF
Run Run Trema Test
ODP
Testing Wi-Fi with OSS Tools
PDF
Rust: Reach Further
PPT
Interface between kernel and user space
PPTX
Coscup SDN workshop - mininet
PPTX
Zookeeper Architecture
PPT
Laboratory exercise - Network security - Penetration testing
PDF
DDP - Meteor
PPT
Backtracking Algorithmic Complexity Attacks Against a NIDS
PDF
Hands-on ethernet driver
PPTX
Elephants and Mice
KEY
Non blocking io with netty
PPTX
Open v switch20150410b
PDF
TCP Sockets Tutor maXbox starter26
PDF
FS2 mongo reactivestreams
PDF
New Virtualization Technologies
PDF
LibreSSL, one year later
SDN Training - Open daylight installation + example with mininet
cpu-affinity
Python twisted
Run Run Trema Test
Testing Wi-Fi with OSS Tools
Rust: Reach Further
Interface between kernel and user space
Coscup SDN workshop - mininet
Zookeeper Architecture
Laboratory exercise - Network security - Penetration testing
DDP - Meteor
Backtracking Algorithmic Complexity Attacks Against a NIDS
Hands-on ethernet driver
Elephants and Mice
Non blocking io with netty
Open v switch20150410b
TCP Sockets Tutor maXbox starter26
FS2 mongo reactivestreams
New Virtualization Technologies
LibreSSL, one year later
Ad

Viewers also liked (7)

PDF
Building a team by Doina Leca
PDF
Piotr Szotkowski about "Bits of ruby"
PDF
Piotr Szotkowski about "Ruby smells"
PDF
04 (IDNOG02) Cloud Infrastructure by Dondy Bappedyanto
PDF
Handout1
PPTX
Open Data in Indonesia - ODDC Research Update
PDF
Lets build a game (in 24 min) by Ivan Zarea
Building a team by Doina Leca
Piotr Szotkowski about "Bits of ruby"
Piotr Szotkowski about "Ruby smells"
04 (IDNOG02) Cloud Infrastructure by Dondy Bappedyanto
Handout1
Open Data in Indonesia - ODDC Research Update
Lets build a game (in 24 min) by Ivan Zarea
Ad

Similar to Building Distributed Systems (20)

PPTX
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
PPTX
DCUS17 : Docker networking deep dive
PDF
IBM IMPACT 2014 - AMC-1883 - Where's My Message - Analyze IBM WebSphere MQ Re...
PDF
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
PPTX
Being HAPI! Reverse Proxying on Purpose
PPTX
Hazelcast and MongoDB at Cloud CMS
DOCX
Remote Procedure Call
PDF
Network-Connected Development with ZeroMQ
 
PDF
Fire & Ice: Making and Breaking macOS Firewalls
PDF
Non-blocking I/O, Event loops and node.js
PDF
Automating the Network
PPTX
Real World Lessons on the Pain Points of Node.JS Application
PDF
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
PDF
ONOS SDN Controller - Introduction
PDF
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
PDF
Node.js - async for the rest of us.
PDF
ICCT2017: A user mode implementation of filtering rule management plane using...
PDF
Flow based programming in golang
PDF
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
PDF
Import golang; struct microservice
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
DCUS17 : Docker networking deep dive
IBM IMPACT 2014 - AMC-1883 - Where's My Message - Analyze IBM WebSphere MQ Re...
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
Being HAPI! Reverse Proxying on Purpose
Hazelcast and MongoDB at Cloud CMS
Remote Procedure Call
Network-Connected Development with ZeroMQ
 
Fire & Ice: Making and Breaking macOS Firewalls
Non-blocking I/O, Event loops and node.js
Automating the Network
Real World Lessons on the Pain Points of Node.JS Application
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
ONOS SDN Controller - Introduction
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Node.js - async for the rest of us.
ICCT2017: A user mode implementation of filtering rule management plane using...
Flow based programming in golang
You need Event Mesh, not Service Mesh - Chris Suszynski [WJUG 301]
Import golang; struct microservice

More from Pivorak MeetUp (20)

PDF
Lisp(Lots of Irritating Superfluous Parentheses)
PDF
Some strange stories about mocks.
PDF
Business-friendly library for inter-service communication
PDF
How i was a team leader once
PDF
Rails MVC by Sergiy Koshovyi
PDF
Introduction to Rails by Evgeniy Hinyuk
PPTX
Ruby OOP (in Ukrainian)
PDF
Testing in Ruby
PDF
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
PDF
The Saga Pattern: 2 years later by Robert Pankowecki
PDF
Data and Bounded Contexts by Volodymyr Byno
PDF
Successful Remote Development by Alex Rozumii
PDF
Origins of Elixir programming language
PDF
Functional Immutable CSS
PDF
Multi language FBP with Flowex by Anton Mishchuk
PDF
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
PDF
CryptoParty: Introduction by Olexii Markovets
PDF
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
PDF
GIS on Rails by Oleksandr Kychun
PDF
Unikernels - Keep It Simple to the Bare Metal
Lisp(Lots of Irritating Superfluous Parentheses)
Some strange stories about mocks.
Business-friendly library for inter-service communication
How i was a team leader once
Rails MVC by Sergiy Koshovyi
Introduction to Rails by Evgeniy Hinyuk
Ruby OOP (in Ukrainian)
Testing in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
The Saga Pattern: 2 years later by Robert Pankowecki
Data and Bounded Contexts by Volodymyr Byno
Successful Remote Development by Alex Rozumii
Origins of Elixir programming language
Functional Immutable CSS
Multi language FBP with Flowex by Anton Mishchuk
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
CryptoParty: Introduction by Olexii Markovets
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
GIS on Rails by Oleksandr Kychun
Unikernels - Keep It Simple to the Bare Metal

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Digital Strategies for Manufacturing Companies
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
System and Network Administration Chapter 2
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Nekopoi APK 2025 free lastest update
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administraation Chapter 3
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Transform Your Business with a Software ERP System
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Operating system designcfffgfgggggggvggggggggg
Digital Strategies for Manufacturing Companies
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
System and Network Administration Chapter 2
Odoo Companies in India – Driving Business Transformation.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Nekopoi APK 2025 free lastest update
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Online Work Permit System for Fast Permit Processing
L1 - Introduction to python Backend.pptx
System and Network Administraation Chapter 3

Building Distributed Systems