Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Highly Scalable Apps in the Cloud

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Building Highly Scalable Apps in the Cloud

A talk for devtalks.ro about why you should design to scale and how the cloud can help you by providing cost-effective systems.

Avatar for Luke Briner

Luke Briner

May 16, 2018

Other Decks in Technology

Transcript

  1. CONTENTS  Why do we need to scale?  Optimising

    performance  Optimising architecture  Using the cloud  Automation
  2. RESOURCES  CPU  RAM  Network bandwidth  Disk

    space  Disk speed  Server handles, threads, cores etc.
  3. AVAILABILITY  Servers die or restart  Components (disks, motherboards

    etc.) break  Networks get flooded  Internet connections or service providers sometimes fail  Denial of Service attacks can saturate your bandwidth  Other types of attacks can take your servers down or make you switch them off
  4. PERFORMANCE  Serving lots of content  Serving all of

    the static assets from the app server  Dealing with random slowdowns (espVMs)
  5. EXAMPLES  Amazon – can’t run 1 server – business

    critical availability  Medium – Maybe not business critical but might still have high number of users  Google – performance is everything  Xero – high user numbers, geographically distributed  Uber –Very high user numbers, generally low data per-user  Ticketmaster –Very high and variable system loads  Github – High user numbers, business critical and a target for attackers  Your company?
  6. OPTIMISING FOR PERFORMANCE  Not having stupidly big page impressions

    (e.g. Amazon 226 requests 6.4MB!)  Bundling resources into single files  Minifying resources to reduce size  Use of client caching (HTTP cache headers)  Optimising images to use high compression formats etc.  Clever use of preload and post-load of assets  YSlow
  7. BUT…  Optimising will help some of these problems (e.g.

    performance)  Resources will go further but not infinitely!  It will not help some of them (e.g. availability, large load swings)  It can only go so far – maybe make a site 10 times better
  8. OPTIMISING ARCHITECTURE - SCALING  This is not Rocket Science

    but it can get complicated  The foundation for high scalability is “scaling out”*  Easiest way is to do this at the web server end  Involves a Load Balancer*  Almost always you will need to share session  You probably cannot afford a system that will take over the world so just look to the next level.
  9. SCALING DATABASES  Scaling databases out is hard!  All

    distributed databases trade-off performance for consistency  At one extreme, you write to a single node and don’t care if the other nodes are out of date for a period of time.  At the other extreme, you have to wait for all nodes (or a majority of them) to be updated before the operation is complete.  If you have more than one writable database, you have to handle conflicts with data that is written to each database. If you can design to avoid conflicts, you will live longer!
  10. PARTITIONING WITH NOSQL  NoSQL is not really the correct

    name! It should be NoReferentialIntegrity but that is more of a mouthful!  NoSQL removes one of the main difficulties in scaling databases – the symbolic links between tables and foreign keys.  Without links, databases can be easily separated into separate “blobs” that can be stored in multiple locations and/or servers.  They don’t solve the problems with multi-geographic locations and multi-master conflict resolution, but they allow performance in a single location to scale almost without limits.  How? By ensuring that our database connection “knows” which part of the database to query for our document!
  11. RAM CACHE  You probably all know that RAM is

    fast  It is also expensive!  By understanding our applications, we should know what is frequently accessed and what can be cached, even for a short time  At PixelPin, we cache user information during a login for 30 seconds. Long enough to do a login but not so long that we end up with stale data  Our client data is cached for 30 minutes since it is not updated often.  Session should live in some kind of RAM  We use Redis for both session information and object caching
  12. PERFORMANCE AND CONSISTENCY  Performance and consistency are always a

    compromise with very high scaled applications, particularly when geographically distributed.  Performance will always need to be acceptable however!  You might well need some special hybrid systems that combine asynchronous operations, such as a queue, with protections for stale data and cache busting.  In our system, one example is the end of registration where the write from Japan might be noticeably slow – we can use UX to get around this – poor performance is acceptable at the end of registration  Counting the number of login attempts cannot incur the same performance overhead so we use a combination of local caching and asynchronous writing for this.
  13. MEASURE EVERYTHING  As you get into more complex systems,

    the time and money can start going up significantly  Pre-optimising easy things like using CDNs is fine  Super-optimising should only be done with measurement  How can you measure performance? What tools do you have?  Measure a baseline, it might show up things you didn’t expect  Performance testing is hard!  Do you have enough access to your data centres to measure everything you need to? What about a service provider’s bandwidth?  Do you know how far your system can scale before new architecture?
  14. THE CLOUD –WHAT IT IS  Services that are abstracted

    – e.g. SQL Azure, Azure Redis, CosmosDB, App Services  Services that are optimised for specific workloads  Pay-as-you-use  Quick and easy to spin up services  Heavy use of automation and APIs for management  Easy to automatically scale  (+ all the benefits of good service providers)
  15. THE CLOUD –WHAT IT IS NOT  Just another name

    for a “rack space” company  A single entity or thing  Not just public infrastructure-as-a-service  Infrastructure-as-a-service  Cloud != Amazon Web Services
  16. WHY IT WORKS FOR MANY COMPANIES  No up-front cost

    (compare to your own data centres!)  Maintenance and support included  Total cost of ownership generally lower  Elastic capacity without paying for the hardware  PaaS can remove a lot of required skills from your workforce  Have you ever managed Windows updates?  Access to hardware for short periods that would be unaffordable
  17. CLOUD VS ON-PREMISES Cloud  Upfront building = $0 

    Mains/backup = $0  Maintenance staff = included  Equipment cost = $included  Running cost = $500-$3000/month  Total - < $36K/year On premises  Upfront building = $50K  Mains/backup = $50K  Maintenance staff = $400K/year  Equipment cost = $200K ($40K/year)  Running cost = $500/month  Total - $100K + $446K/year
  18. CLOUD VS DATA CENTRE Cloud  Upfront building = $0

     Mains/backup = $0  Maintenance staff = included  Equipment cost = $included  Running cost = $500-$3000/month Total - < $36K/year Data Centre  Upfront building = $0  Mains/backup = $0  Maintenance staff = $120K/year  Equipment cost = $200K ($40K/year)  Running cost = $500/month Total - $220K/year
  19. THINGS TO BE CAREFUL OF  Service abstractions can lead

    to vendor lock-in  Some vendors support certain services better than others  You do not have direct control over the equipment  You have to be able to trust the vendors certifications  Pricing models can vary massively: fixed, data, per server, per domain  e.g. Using NoSQL for session was very expensive since priced per operation  Will require a skillset that you won’t already have e.g. how to automate DNS setup or configure auto-scaling  Don’t make assumptions about performance e.g. autoscaling is not usually super fast.
  20. REDISVS COSMOSDB Redis  Standard C1  1GB  No

    usage fees  €87/month CosmosDB  400 resource units/second (1600)  <= 10GB  €20/month (€80)  21c/month for 1GB
  21. WHEN THE CLOUD DOESN’T WORK  Specialised security requirements –

    e.g. military spec  Portable systems that need to work without internet  Very high volumes where you can afford to take on staff and super-optimise  Some super specialised applications when hardware is not available on cloud  Simple, always-on, highly changeable systems such as Development servers  When you can’t find a pricing model that works for your workload  When a vendor does not provide suitable data segregation  When you don’t trust the vendor or their governments to leave your data alone  Corporates who don’t understand what the cloud is
  22. AUTOMATION  One of the biggest tools for DevOps is

    automation  Most cloud vendors have rich APIs to interact with their infrastructure  Support most languages  Automation and scripting should be a requirement for most Developers  Consider how to deploy an entire environment e.g. for performance or pen testing.  Investigate how you might use your existing or new CI/CD tools with your selected vendor.  Consider how your workflows fit or might need changing to work with the cloud.
  23. EXAMPLE: AZURE RESOURCE MANAGER  Azure’s resource manager allows you

    to automate whole groups of services  A json description, which Azure will turn into your services  Can be invoked from script  BUT  Tooling is fairly basic – intellisense is variable  Exporting an existing system description does not export everything  Debugging can be slow (deploy, check, fix)  Trying to work out how to wire up, say, a new database connection string to a web application settings is not always straight-forward
  24. EXAMPLE: AWS IDENTITY ACCESS MANAGEMENT (IAM)  Powerful control over

    users, keys and access controls  BUT  Web gui is poor  Navigation can be hard  Debugging is not easy  Understanding IAM-led permissions and resource-led permissions not easy  Basically a json document with a few basic tools
  25. CONCLUSION  Unless you have something very simple, you should

    design to scale – imagine the maximum number of users your system could end up with  Someone needs to understand architecture to design it well  If you want to scale up to more than 1000000 users, you will probably need to use the cloud  Choose the cloud carefully since they will all have pros and cons – pricing is only one aspect  Understanding the correct choice of cloud services can save you much time, money and difficulty.  If you become as big as Facebook, you won’t need my advice and are welcome to build your own data centres.