SlideShare a Scribd company logo
1 of 19
Download to read offline
Scaling Symfony
From single to multi-node cluster
Antoni Orfin
antoniorfin@gmail.com
THEORY
Scaling types
1. Vertical Scaling
2. Horizontal Scaling
THEORY
Scaling types
Real life:
Vertical ! horizontal
SCALABILITY PATH
0. Caching
HTTP Cache
1. Browser cache (private)
2. Proxy cache (shared)
0
1st Tier Cache – Reverse Proxy
Caches HTTP responses. Most performant, close to the user.
E.g. Varnish
1
$response = new Response;
$response->setMaxAge(600); // For user’s browser
$response->setSharedMaxAge(600); // For reverse proxy
$response->setVary([’User-Agent’]); // Reverse proxy should cache
// different responses for UA
@Cache(smaxage=”15”, // Configure using annotations
vary={”User-Agent”})
2nd Tier Cache – in-application
Caches database query results, long-term operations.
E.g. Redis, Memcache (mostly in-memory)
2
App DB
App
Db
Single server
with Application (PHP, Symfony)
and Database (MySQL)
Separated servers
servers separated by their roles
Beware of ping between app
and DB "
SCALABILITY PATH
1. Separating servers
$ htop
F4 (filter): mysql
collectd
SCALABILITY PATH
1. Separating servers When?
# parameters.yml
parameters:
database_host: localhost
…
# parameters.yml
parameters:
database_host: db.pixers
…
SCALABILITY PATH
1. Separating servers How?
Ask your *ops to set-up new db server1
Change database host in configuration2
App1App1 AppN…
Load Balancers
Distribute requests to backend
servers, e.g. HAProxy, Varnish
Application servers
Each has the same application
(clones)
SCALABILITY PATH
2. Adding application servers
lb1 lb2
DNS
DNS Server
Distributes requests to Load
Balancers
DNS Load Balancing1
Load Balancing software
e.g. HAProxy, Varnish, nginx
2
$ dig a microsoft.com
...
;; ANSWER SECTION:
microsoft.com. 924 IN A 104.40.211.35
microsoft.com. 924 IN A 104.43.195.251
microsoft.com. 924 IN A 191.239.213.197
microsoft.com. 924 IN A 23.96.52.53
microsoft.com. 924 IN A 23.100.122.175
SCALABILITY PATH
2. Adding application servers How?
Session handling
Losing users’ session? Sticky sessions?
3
Saving files
Using distributed filesystem (Amazon S3, CEPH or just NFS)
4
$ composer require knplabs/knp-gaufrette-bundle ~0.3
$ composer require oneup/flysystem-bundle @stable
$ composer require snc/redis-bundle 2.x-dev
SymfonyComponentHttpFoundationSessionStorage
HandlerMemcachedSessionHandler
SCALABILITY PATH
2. Adding application servers How?
db2
master
db1
master
Master-Master replication
Writes to db1 or db2
Reads from db1 or db2
+ High-availability
+ Better performance in writes and reads
- Generating IDs (auto_increment_offset)
- Failover mechanism?
Master-Slave replication
Writes to db1
Reads from db1 or db2
+ High-availability
+ Better performance in reads
+ Easier than master/master
- Failover mechanism?
SCALABILITY PATH
3. Scaling database - Replication
db2
slave
db1
master
Multiple databases
Data partitioned by type
+ More space for data
+ Better performance in reads
- Not transparent for application (99% cases)
- Beware of JOINs (app-side)
SCALABILITY PATH
3. Scaling database - Sharding
db
products
db orders
App
SCALABILITY PATH
3. Scaling database – Sharding in SaaS
db
tenant2
db
tenant1
App
Multiple databases
Data partitioned by tenants
db core
SCALABILITY PATH
3. Scaling database How?
Sharding
+ Dynamic connections (SaaS/Multitenant)
+ Multiple entity managers
1
Replication - Doctrine2
# app/config/config.yml
doctrine:
dbal:
connections:
default:
slaves:
slave1: # ...
slave2:
SCALABILITY PATH
Final architecture?
SCALABILITY PATH
4. Going SOA
Core Application
PrintAPI PhotoAPI
SCALABILITY PATH
4. Going SOA When?
Pros:
+ New business opportunities
+ Better scalability as services are stateless
+ Exposing API by SOAP or REST
+ Easier development (dev-team per service)
+ Technology independent (Symfony app can use Node.js service)
Cons:
- Platform complexity – harded to maintain
- Communication overhead
- Security?
1
2
SCALABILITY PATH
4. Going SOA How?
Service-side (e.g. Search application)1
Client-side (e.g. Core application)2
$ composer require guzzlehttp/guzzle
$ composer require eightpoints/guzzle-bundle
(we don’t use it)
$ composer require friendsofsymfony/rest-bundle
(we don’t use it in every project)
$ composer require jms/serializer-bundle
$ composer require nelmio/api-doc-bundle
Contact me at:
antoniorfin@gmail.com
linkedin.com/in/antoniorfin
twitter.com/antoniorfin
www.pixersize.com
Thank you!
Questions & Answers

More Related Content

Viewers also liked

MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
Raul Fraile
 
Principles of PHP Package Design (for AmsterdamPHP)
Principles of PHP Package Design (for AmsterdamPHP)Principles of PHP Package Design (for AmsterdamPHP)
Principles of PHP Package Design (for AmsterdamPHP)
Matthias Noback
 

Viewers also liked (20)

Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
 
MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
 
(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et Tolerance(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et Tolerance
 
Principles of PHP Package Design (for AmsterdamPHP)
Principles of PHP Package Design (for AmsterdamPHP)Principles of PHP Package Design (for AmsterdamPHP)
Principles of PHP Package Design (for AmsterdamPHP)
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Building large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor frameworkBuilding large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor framework
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Docker deploy
Docker deployDocker deploy
Docker deploy
 
ReactをRailsとどっぷり使ってみた話と、フロントエンド×AWSのこれから
ReactをRailsとどっぷり使ってみた話と、フロントエンド×AWSのこれからReactをRailsとどっぷり使ってみた話と、フロントエンド×AWSのこれから
ReactをRailsとどっぷり使ってみた話と、フロントエンド×AWSのこれから
 
Implementing High Availability Caching with Memcached
Implementing High Availability Caching with MemcachedImplementing High Availability Caching with Memcached
Implementing High Availability Caching with Memcached
 
Frontera: open source, large scale web crawling framework
Frontera: open source, large scale web crawling frameworkFrontera: open source, large scale web crawling framework
Frontera: open source, large scale web crawling framework
 
Interoperability and Portability for Cloud Computing: A Guide
Interoperability and Portability for Cloud Computing: A GuideInteroperability and Portability for Cloud Computing: A Guide
Interoperability and Portability for Cloud Computing: A Guide
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architecture
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS
 
Magento scalability from the trenches (Meet Magento Sweden 2016)
Magento scalability from the trenches (Meet Magento Sweden 2016)Magento scalability from the trenches (Meet Magento Sweden 2016)
Magento scalability from the trenches (Meet Magento Sweden 2016)
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & Ansible
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Scaling Symfony - From single to multi-node cluster

  • 1. Scaling Symfony From single to multi-node cluster Antoni Orfin antoniorfin@gmail.com
  • 2. THEORY Scaling types 1. Vertical Scaling 2. Horizontal Scaling
  • 4. SCALABILITY PATH 0. Caching HTTP Cache 1. Browser cache (private) 2. Proxy cache (shared) 0 1st Tier Cache – Reverse Proxy Caches HTTP responses. Most performant, close to the user. E.g. Varnish 1 $response = new Response; $response->setMaxAge(600); // For user’s browser $response->setSharedMaxAge(600); // For reverse proxy $response->setVary([’User-Agent’]); // Reverse proxy should cache // different responses for UA @Cache(smaxage=”15”, // Configure using annotations vary={”User-Agent”}) 2nd Tier Cache – in-application Caches database query results, long-term operations. E.g. Redis, Memcache (mostly in-memory) 2
  • 5. App DB App Db Single server with Application (PHP, Symfony) and Database (MySQL) Separated servers servers separated by their roles Beware of ping between app and DB " SCALABILITY PATH 1. Separating servers
  • 6. $ htop F4 (filter): mysql collectd SCALABILITY PATH 1. Separating servers When?
  • 7. # parameters.yml parameters: database_host: localhost … # parameters.yml parameters: database_host: db.pixers … SCALABILITY PATH 1. Separating servers How? Ask your *ops to set-up new db server1 Change database host in configuration2
  • 8. App1App1 AppN… Load Balancers Distribute requests to backend servers, e.g. HAProxy, Varnish Application servers Each has the same application (clones) SCALABILITY PATH 2. Adding application servers lb1 lb2 DNS DNS Server Distributes requests to Load Balancers
  • 9. DNS Load Balancing1 Load Balancing software e.g. HAProxy, Varnish, nginx 2 $ dig a microsoft.com ... ;; ANSWER SECTION: microsoft.com. 924 IN A 104.40.211.35 microsoft.com. 924 IN A 104.43.195.251 microsoft.com. 924 IN A 191.239.213.197 microsoft.com. 924 IN A 23.96.52.53 microsoft.com. 924 IN A 23.100.122.175 SCALABILITY PATH 2. Adding application servers How?
  • 10. Session handling Losing users’ session? Sticky sessions? 3 Saving files Using distributed filesystem (Amazon S3, CEPH or just NFS) 4 $ composer require knplabs/knp-gaufrette-bundle ~0.3 $ composer require oneup/flysystem-bundle @stable $ composer require snc/redis-bundle 2.x-dev SymfonyComponentHttpFoundationSessionStorage HandlerMemcachedSessionHandler SCALABILITY PATH 2. Adding application servers How?
  • 11. db2 master db1 master Master-Master replication Writes to db1 or db2 Reads from db1 or db2 + High-availability + Better performance in writes and reads - Generating IDs (auto_increment_offset) - Failover mechanism? Master-Slave replication Writes to db1 Reads from db1 or db2 + High-availability + Better performance in reads + Easier than master/master - Failover mechanism? SCALABILITY PATH 3. Scaling database - Replication db2 slave db1 master
  • 12. Multiple databases Data partitioned by type + More space for data + Better performance in reads - Not transparent for application (99% cases) - Beware of JOINs (app-side) SCALABILITY PATH 3. Scaling database - Sharding db products db orders App
  • 13. SCALABILITY PATH 3. Scaling database – Sharding in SaaS db tenant2 db tenant1 App Multiple databases Data partitioned by tenants db core
  • 14. SCALABILITY PATH 3. Scaling database How? Sharding + Dynamic connections (SaaS/Multitenant) + Multiple entity managers 1 Replication - Doctrine2 # app/config/config.yml doctrine: dbal: connections: default: slaves: slave1: # ... slave2:
  • 16. SCALABILITY PATH 4. Going SOA Core Application PrintAPI PhotoAPI
  • 17. SCALABILITY PATH 4. Going SOA When? Pros: + New business opportunities + Better scalability as services are stateless + Exposing API by SOAP or REST + Easier development (dev-team per service) + Technology independent (Symfony app can use Node.js service) Cons: - Platform complexity – harded to maintain - Communication overhead - Security? 1 2
  • 18. SCALABILITY PATH 4. Going SOA How? Service-side (e.g. Search application)1 Client-side (e.g. Core application)2 $ composer require guzzlehttp/guzzle $ composer require eightpoints/guzzle-bundle (we don’t use it) $ composer require friendsofsymfony/rest-bundle (we don’t use it in every project) $ composer require jms/serializer-bundle $ composer require nelmio/api-doc-bundle