Scale up
Pedro Machado – Soft. Developer
pedro.machado@imobilemagic.com
How To Scale
• Vertical Scaling (Scale Up)
• Upgrade the server hardware
• Throw in more RAM, faster disk(s), CPU, etc
• Horizontal Scaling (Scale Out)
• Spin up another server instance
Vertical Scaling
• Advantages
• No code changes required
• Easy and fast to do – AWS
• No need to manage multiple machines
• Disadvantages
• Expensive
• Single point of failure
• Vendor lock-in
Horizontal Scaling
• Advantages
• Continuous availability/redundancy
• Continuous upgrades, with no downtime
• Better perfomance
• Disadvantages
• May required code/architectural changes
• Manage multiple machines
• Developing distributed systems can be complex
Before Scaling
• Cache, cache and cache!
• AWS – ElastiCache, Memcached, Redis
• Avoid unnecessary queries
• Tune your server / application
• Use indexes, wisely
• EXPLAIN SELECT * FROM Table WHERE name = ‘John’;
• Find and fix your bottlenecks
Database Scaling
• Sharding :
• Distribute table rows onto different servers
• Example: Customer table -> US customers are on ServerUS, EU customers on
ServerEU
• Partitioning
• Master-slave
• Inserts and Updates go to the master, reads go to the slave
• The single Master server is a limitation to scalability. Can quickly create a
bottleneck.
• Near real time – if master dies data may be lost.
Server Scaling – Microservices
Server Scaling – Microservices
• The pros
• A service should only do one thing and do it well
• A service is fully independent - self contained
• Has it’s own database type and tech stack (language agnostic)
• Fast deploys, tiny EAR = super fast deploy
• Loosely coupled - communicate asynchronously via messages/events,
queues or REST (sync)
• Self monitoring, e.g. Circuit Breaker, Bulkhead
• Greater resiliency – fault isolation
• Independent dev teams
Server Scaling – Microservices
• The cons
• Service discovery
• Distributed services are complex to deal with
• Fan out of requests
• 1 request in a monolithic application can be equal to multiple requests in a
microservices architecture
• Serialization overhead
• Latency
General Tips
• Monitor your server resources
• Set and configure alarms
• Elastic scaling
• Use AWS auto-scaling feature in conjunction with CloudWatch
• When X metric is above the limit-> spin up another instance
• When X metric is back to normal values -> kill an instance to save up costs
• https://www.youtube.com/watch?v=7SfVZqOVcCI
iMobileMagic Teck Talk Scale Up

iMobileMagic Teck Talk Scale Up

  • 2.
    Scale up Pedro Machado– Soft. Developer pedro.machado@imobilemagic.com
  • 3.
    How To Scale •Vertical Scaling (Scale Up) • Upgrade the server hardware • Throw in more RAM, faster disk(s), CPU, etc • Horizontal Scaling (Scale Out) • Spin up another server instance
  • 4.
    Vertical Scaling • Advantages •No code changes required • Easy and fast to do – AWS • No need to manage multiple machines • Disadvantages • Expensive • Single point of failure • Vendor lock-in
  • 5.
    Horizontal Scaling • Advantages •Continuous availability/redundancy • Continuous upgrades, with no downtime • Better perfomance • Disadvantages • May required code/architectural changes • Manage multiple machines • Developing distributed systems can be complex
  • 6.
    Before Scaling • Cache,cache and cache! • AWS – ElastiCache, Memcached, Redis • Avoid unnecessary queries • Tune your server / application • Use indexes, wisely • EXPLAIN SELECT * FROM Table WHERE name = ‘John’; • Find and fix your bottlenecks
  • 7.
    Database Scaling • Sharding: • Distribute table rows onto different servers • Example: Customer table -> US customers are on ServerUS, EU customers on ServerEU • Partitioning • Master-slave • Inserts and Updates go to the master, reads go to the slave • The single Master server is a limitation to scalability. Can quickly create a bottleneck. • Near real time – if master dies data may be lost.
  • 8.
    Server Scaling –Microservices
  • 9.
    Server Scaling –Microservices • The pros • A service should only do one thing and do it well • A service is fully independent - self contained • Has it’s own database type and tech stack (language agnostic) • Fast deploys, tiny EAR = super fast deploy • Loosely coupled - communicate asynchronously via messages/events, queues or REST (sync) • Self monitoring, e.g. Circuit Breaker, Bulkhead • Greater resiliency – fault isolation • Independent dev teams
  • 10.
    Server Scaling –Microservices • The cons • Service discovery • Distributed services are complex to deal with • Fan out of requests • 1 request in a monolithic application can be equal to multiple requests in a microservices architecture • Serialization overhead • Latency
  • 11.
    General Tips • Monitoryour server resources • Set and configure alarms • Elastic scaling • Use AWS auto-scaling feature in conjunction with CloudWatch • When X metric is above the limit-> spin up another instance • When X metric is back to normal values -> kill an instance to save up costs • https://www.youtube.com/watch?v=7SfVZqOVcCI