SlideShare uma empresa Scribd logo
1 de 40
Scalable web apps
execution time
vs
development time

Piotr Pelczar
me@athlan.pl
Types of scaling
Vertical scaling

Horizontal scaling

scale up

scale out
Think about your app as a worker
not single instance
OS

Load balancer

App

Server #1

App #1

App #2

Server #2
App #3

App #4

Server #3

App #5
Think about your app as a worker
not single instance
Load balancer

Server #1
App #1

Server #3
Load balancer

App #2

Server #2
App #3

App #4

App #5

Server #n
Sessions
We need:
• Common
• Fast
• Persistent

Storage for sessions.
Sessions

OS

Load balancer

App

Server #1

App #1

App #2

Server #2
App #3

Session storage

App #4

Server #3

App #5
Sessions - Redis

•
•
•
•
•

Key-value in memory database (hash-tabled)
Scalable up to 1k nodes
Partitioning with Query routing
Non blocking M-S replication on nodes
Clustered (currently not production ready)

http://athlan.pl/symfony2-redis-session-handler/
Redis - Partitioning with Query routing
Query
random
node

Miss

Node #1

Hit, abort

Node #2

Node #3

Also supported:
• Client-side partitioning (app calls appropriate
node)
• Proxy assisted partitioning (proxy selects
appropriate node)
Centralized Logging
• Logs should be centrailzed to avoid taking
notice to each node separately
• Approaches:
– File replication (rsync + cron)
– syslog (easy to integrate with log4j)
• syslogd over UDP p:514
• rsyslog over TCP, stores data in db
Common storage, no local changes!
• Keep storage avaliable to all nodes
– Symfony2 Gaufrette Bundle
•
•
•
•
•

FTP
Amazon S3
OpenCloud
AzureBlobStorage
Rackspace
Architecture
OS

Load balancer

App

Server #1
App #1

App #2

OS

Session storage

Server #2
App #3

App #4

Server #3
App #5

Files storage abstraction

Centralized logging
Continuous Integration
• To keep all nodes up-to-date, you need CI
• Automatize disabling nodes, building,
deploying
– Jenkins CI
Contineous Integration
1. Disable service on node
2. Deploy/build app
1. Copy files
2. Update db schema (liquibase, ORM schema
update)
3. Execute scripts

3. Re-run service
Balance the payload - HAProxy
Yeah guys, this is logo :)
But no schema is needed
just imagine how it works.

• Very, very fast proxy!
• Software TCP/HTTP load balancer
• Different node selecting algorithms:
– roudrobin (limit 4128)
– static-rr
– leastconn (lowest number of connections)
Balance the payload - HAProxy
• You can check node’s status by pinging
• Dead node is excluded from balancing strategy
vi /etc/haproxy/haproxy.cfg
option httpchk HEAD /check.txt HTTP/1.0
server webA 192.168.0.102:80 check
server webB 192.168.0.103:80 check
Balance the payload - HAProxy
• Monitor node’s status by read stats from
socket via socat.

echo "show stat" | socat
/tmp/haproxy.sock stdio
Balance the payload - HAProxy
• Monitor node’s status by native stats webapp
console
Nodes Monitoring - Zabbix
• Zabbix, centralized server monitoring
Zabbix + HAProxy
• UserParameter=haproxy.qcur[*],
echo "show stat" | socat
/tmp/haproxy.sock stdio | grep -i
'$1' | sed 's/,/ /g' | awk
'{print $$3}'
Reverse Proxy and Varnish cache
• Global virtual user = global cache

http://tomayko.com/writings/things-caches-do
Reverse Proxy – Expiration model

http://tomayko.com/writings/things-caches-do
Reverse Proxy – Expiration model

http://tomayko.com/writings/things-caches-do
Reverse Proxy – Validation model

http://tomayko.com/writings/things-caches-do
Reverse Proxy – Validation model

http://tomayko.com/writings/things-caches-do
Reverse Proxy and Varnish cache

Apache
:81

Varnish
:80

App
Reverse Proxy and Varnish cache
Apache
:8081
Varnish
:8080

App

HAProxy
:80
Apache
:8083
Varnish
:8082

App
Reverse Proxy and Varnish cache
Apache
:8081

App

Varnish
:80

HAProxy
:81
Apache
:8082

App
Varnish and ESI
<!DOCTYPE html>
<html>
<body>
<!-- ... some content -->
<!-- Embed the content of another page here -->
<esi:include src="http://..." />
<!-- ... more content -->
</body>
</html>
Scaling databases - Master slave
Write
Master

Slave

Read

• All data redundancy

Slave

Slave
MongoDB scaling
• Common models to spread data over nodes:
– range keys
– hash keys

• Many nodes on cheap machines
• No all data redundancy in each node
MongoDB – range-based keys

http://docs.mongodb.org

• Awesome for range queries (grab data from min nodes –
Query isolation)
• Not good enough to distribute data over nodes in case of
monotinic incemental
MongoDB – hash-based keys

http://docs.mongodb.org

• Take notice: not good for range queries while
merge-sorting, no Query isolation in this case
• Write scaling – Write to many nodes simultaneously (take
notice to readers-writer lock, where write is exclusive)
Mongodb sharding and clustering

http://docs.mongodb.org
CQRS
• Command Query Responsibility Segregation
– separate application service layers for writing and
readng from DB (possibility to use different data
sources like RAM or DB)
CQRS
• Examples
– post-insert population cache
• all SELECTs are from cache (even invalid)
• consider LFU instead of LRU to invaidate cache

– pre-insert into memory
• dump results periodicaly

In both approaches there is convenient to use
Queues or data bus !
Queues, RabbitMQ
• RabbitMQ is based on AMQP (Advanced
Message Queuing Protocol)
– point-to-point
– publish-and-subscribe
– queueing, routing

• AMQP is not JMS (Java Message Service is an
API, not protocol)
• Happy Rabit is empty Rabbit
– do not try to store any data (messages) in queue
system in persistent mode to keep HA
Queues, RabbitMQ
• Simple queue
• Work queues
(one consumer)

• Publish/Subscribe
(many consumers)
Box vs spread architecture.
• Box architecture
– no scaling
– easy to maintenance
Server

Webapp

Redis

RabbitMQ

Varnish

DB
Box vs spread architecture.
• Spread architecture
– High availability
– more integrations, more administrative
Server #1
RabbitMQ

Redis

HAProxy

Server #2

Server #3

Webapp

Webapp

DB shard

Varnish

DB shard

Varnish
Scalable web apps
execution time
vs
development time

Piotr Pelczar
me@athlan.pl

Mais conteúdo relacionado

Mais procurados

Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013
Jan Gehring
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
Mahendra M
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 

Mais procurados (20)

introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Treasure Data Summer Internship Final Report
Treasure Data Summer Internship Final ReportTreasure Data Summer Internship Final Report
Treasure Data Summer Internship Final Report
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Vert.x v3 - high performance polyglot application toolkit
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkit
 
Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013
 
Node ppt
Node pptNode ppt
Node ppt
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Massively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHPMassively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHP
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loop
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit
 

Semelhante a Scalable Web Apps

Semelhante a Scalable Web Apps (20)

haproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdfhaproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdf
 
HAProxy
HAProxy HAProxy
HAProxy
 
3.2 Streaming and Messaging
3.2 Streaming and Messaging3.2 Streaming and Messaging
3.2 Streaming and Messaging
 
Conceptos básicos. Seminario web 6: Despliegue de producción
Conceptos básicos. Seminario web 6: Despliegue de producciónConceptos básicos. Seminario web 6: Despliegue de producción
Conceptos básicos. Seminario web 6: Despliegue de producción
 
Right-Sizing your SQL Server Virtual Machine
Right-Sizing your SQL Server Virtual MachineRight-Sizing your SQL Server Virtual Machine
Right-Sizing your SQL Server Virtual Machine
 
HPC Controls Future
HPC Controls FutureHPC Controls Future
HPC Controls Future
 
What no one tells you about writing a streaming app
What no one tells you about writing a streaming appWhat no one tells you about writing a streaming app
What no one tells you about writing a streaming app
 
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)
 
Denser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microserversDenser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microservers
 
Spy hard, challenges of 100G deep packet inspection on x86 platform
Spy hard, challenges of 100G deep packet inspection on x86 platformSpy hard, challenges of 100G deep packet inspection on x86 platform
Spy hard, challenges of 100G deep packet inspection on x86 platform
 
(ATS6-PLAT06) Maximizing AEP Performance
(ATS6-PLAT06) Maximizing AEP Performance(ATS6-PLAT06) Maximizing AEP Performance
(ATS6-PLAT06) Maximizing AEP Performance
 
Apache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutApache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling Out
 
Machine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkMLMachine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkML
 
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
Intro to Apache Apex (next gen Hadoop) & comparison to Spark StreamingIntro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
 
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE PlatformsFIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Hardware Provisioning
Hardware ProvisioningHardware Provisioning
Hardware Provisioning
 
A Closer Look at Apache Kudu
A Closer Look at Apache KuduA Closer Look at Apache Kudu
A Closer Look at Apache Kudu
 

Mais de Piotr Pelczar

Liquibase - database structure versioning
Liquibase - database structure versioningLiquibase - database structure versioning
Liquibase - database structure versioning
Piotr Pelczar
 

Mais de Piotr Pelczar (6)

Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
Elasticsearch - SEARCH & ANALYZE DATA IN REAL TIME
Elasticsearch - SEARCH & ANALYZE DATA IN REAL TIMEElasticsearch - SEARCH & ANALYZE DATA IN REAL TIME
Elasticsearch - SEARCH & ANALYZE DATA IN REAL TIME
 
[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Liquibase - database structure versioning
Liquibase - database structure versioningLiquibase - database structure versioning
Liquibase - database structure versioning
 
CQRS
CQRSCQRS
CQRS
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Scalable Web Apps

  • 1. Scalable web apps execution time vs development time Piotr Pelczar me@athlan.pl
  • 2. Types of scaling Vertical scaling Horizontal scaling scale up scale out
  • 3. Think about your app as a worker not single instance OS Load balancer App Server #1 App #1 App #2 Server #2 App #3 App #4 Server #3 App #5
  • 4. Think about your app as a worker not single instance Load balancer Server #1 App #1 Server #3 Load balancer App #2 Server #2 App #3 App #4 App #5 Server #n
  • 5. Sessions We need: • Common • Fast • Persistent Storage for sessions.
  • 6. Sessions OS Load balancer App Server #1 App #1 App #2 Server #2 App #3 Session storage App #4 Server #3 App #5
  • 7. Sessions - Redis • • • • • Key-value in memory database (hash-tabled) Scalable up to 1k nodes Partitioning with Query routing Non blocking M-S replication on nodes Clustered (currently not production ready) http://athlan.pl/symfony2-redis-session-handler/
  • 8. Redis - Partitioning with Query routing Query random node Miss Node #1 Hit, abort Node #2 Node #3 Also supported: • Client-side partitioning (app calls appropriate node) • Proxy assisted partitioning (proxy selects appropriate node)
  • 9. Centralized Logging • Logs should be centrailzed to avoid taking notice to each node separately • Approaches: – File replication (rsync + cron) – syslog (easy to integrate with log4j) • syslogd over UDP p:514 • rsyslog over TCP, stores data in db
  • 10. Common storage, no local changes! • Keep storage avaliable to all nodes – Symfony2 Gaufrette Bundle • • • • • FTP Amazon S3 OpenCloud AzureBlobStorage Rackspace
  • 11. Architecture OS Load balancer App Server #1 App #1 App #2 OS Session storage Server #2 App #3 App #4 Server #3 App #5 Files storage abstraction Centralized logging
  • 12. Continuous Integration • To keep all nodes up-to-date, you need CI • Automatize disabling nodes, building, deploying – Jenkins CI
  • 13. Contineous Integration 1. Disable service on node 2. Deploy/build app 1. Copy files 2. Update db schema (liquibase, ORM schema update) 3. Execute scripts 3. Re-run service
  • 14. Balance the payload - HAProxy Yeah guys, this is logo :) But no schema is needed just imagine how it works. • Very, very fast proxy! • Software TCP/HTTP load balancer • Different node selecting algorithms: – roudrobin (limit 4128) – static-rr – leastconn (lowest number of connections)
  • 15. Balance the payload - HAProxy • You can check node’s status by pinging • Dead node is excluded from balancing strategy vi /etc/haproxy/haproxy.cfg option httpchk HEAD /check.txt HTTP/1.0 server webA 192.168.0.102:80 check server webB 192.168.0.103:80 check
  • 16. Balance the payload - HAProxy • Monitor node’s status by read stats from socket via socat. echo "show stat" | socat /tmp/haproxy.sock stdio
  • 17. Balance the payload - HAProxy • Monitor node’s status by native stats webapp console
  • 18. Nodes Monitoring - Zabbix • Zabbix, centralized server monitoring
  • 19. Zabbix + HAProxy • UserParameter=haproxy.qcur[*], echo "show stat" | socat /tmp/haproxy.sock stdio | grep -i '$1' | sed 's/,/ /g' | awk '{print $$3}'
  • 20. Reverse Proxy and Varnish cache • Global virtual user = global cache http://tomayko.com/writings/things-caches-do
  • 21. Reverse Proxy – Expiration model http://tomayko.com/writings/things-caches-do
  • 22. Reverse Proxy – Expiration model http://tomayko.com/writings/things-caches-do
  • 23. Reverse Proxy – Validation model http://tomayko.com/writings/things-caches-do
  • 24. Reverse Proxy – Validation model http://tomayko.com/writings/things-caches-do
  • 25. Reverse Proxy and Varnish cache Apache :81 Varnish :80 App
  • 26. Reverse Proxy and Varnish cache Apache :8081 Varnish :8080 App HAProxy :80 Apache :8083 Varnish :8082 App
  • 27. Reverse Proxy and Varnish cache Apache :8081 App Varnish :80 HAProxy :81 Apache :8082 App
  • 28. Varnish and ESI <!DOCTYPE html> <html> <body> <!-- ... some content --> <!-- Embed the content of another page here --> <esi:include src="http://..." /> <!-- ... more content --> </body> </html>
  • 29. Scaling databases - Master slave Write Master Slave Read • All data redundancy Slave Slave
  • 30. MongoDB scaling • Common models to spread data over nodes: – range keys – hash keys • Many nodes on cheap machines • No all data redundancy in each node
  • 31. MongoDB – range-based keys http://docs.mongodb.org • Awesome for range queries (grab data from min nodes – Query isolation) • Not good enough to distribute data over nodes in case of monotinic incemental
  • 32. MongoDB – hash-based keys http://docs.mongodb.org • Take notice: not good for range queries while merge-sorting, no Query isolation in this case • Write scaling – Write to many nodes simultaneously (take notice to readers-writer lock, where write is exclusive)
  • 33. Mongodb sharding and clustering http://docs.mongodb.org
  • 34. CQRS • Command Query Responsibility Segregation – separate application service layers for writing and readng from DB (possibility to use different data sources like RAM or DB)
  • 35. CQRS • Examples – post-insert population cache • all SELECTs are from cache (even invalid) • consider LFU instead of LRU to invaidate cache – pre-insert into memory • dump results periodicaly In both approaches there is convenient to use Queues or data bus !
  • 36. Queues, RabbitMQ • RabbitMQ is based on AMQP (Advanced Message Queuing Protocol) – point-to-point – publish-and-subscribe – queueing, routing • AMQP is not JMS (Java Message Service is an API, not protocol) • Happy Rabit is empty Rabbit – do not try to store any data (messages) in queue system in persistent mode to keep HA
  • 37. Queues, RabbitMQ • Simple queue • Work queues (one consumer) • Publish/Subscribe (many consumers)
  • 38. Box vs spread architecture. • Box architecture – no scaling – easy to maintenance Server Webapp Redis RabbitMQ Varnish DB
  • 39. Box vs spread architecture. • Spread architecture – High availability – more integrations, more administrative Server #1 RabbitMQ Redis HAProxy Server #2 Server #3 Webapp Webapp DB shard Varnish DB shard Varnish
  • 40. Scalable web apps execution time vs development time Piotr Pelczar me@athlan.pl