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

Effortless Serverless - KharkivJS

Effortless Serverless - KharkivJS

What is serverless, how does it work and why should you care? How does it compare to some things we use everyday

This talk explains how we used to build apps and serve them, to what serverless is. It also gets you started quickly, what can you gain from serverless along with where you should use it and where not

Aleksandar Simovic

October 28, 2017
Tweet

More Decks by Aleksandar Simovic

Other Decks in Programming

Transcript

  1. @simalexan BUILDING APPS Customers (Angular) API Admin (Angular) Company site

    (Wordpress) Elastic Search Other services Owners (Angular) PG As engineers, this what we really want to do.
  2. @simalexan SERVING CUSTOMERS What did we use (server-hosted) • Heroku

    • EC2 • Azure Development Staging Production Environments (per server) Building apps is the core, but we have to do run them too.
  3. @simalexan ORGANIZE SERVING CUSTOMERS Customers (Angular) API Admin (Angular) Company

    site (Wordpress) Elastic Search Other services Owners (Angular) PG x 3 Server Server Server Big A** Server
  4. @simalexan PLANNING CUSTOMERS • CAPACITY PLANNING • RENT + CONFIGURE

    MACHINES
 (prepare our servers) • DEPLOYMENT
 ssh, rsync • SCALE, BALANCE
  5. @simalexan WHAT HAPPENED? • Marketing set an unannounced advertising.
 100,000

    new users in 1h > crashed immediately - “Next time, we’ll be better.” • 2 months later
 DDoS attack > 48 service NA • 1 month later. 
 Elastic search overflowed > API crashed > Web apps stuck • Three months later? - “Next time, we’ll be better.”
  6. @simalexan Average API server usage Usage Intervals 35% 60% 80%

    06 09 12 15 18 70% 45% 21 00 03 06 0% 100% This is normal. Good? Price: 100$
  7. @simalexan Average API server WASTED TIME Intervals 65% 40% 20%

    99% 30% 55% 95% 99% 0% 100% Bad enough? Waste 06 09 12 15 18 21 00 03 06
  8. @simalexan UNEXPECTED PEAK? Usage Intervals 35% 60% 110% 70% 45%

    0% 100% New customers are a problem ?! “Unexpected” peak new capacity 06 09 12 15 18 21 00 03 06 =
  9. @simalexan new API server usage Usage Intervals 28% 54% 80%

    63% 38% 0% 100% We are “safe” now! Buffer New Price: 150$ - (if you’re lucky) 06 09 12 15 18 21 00 03 06
  10. @simalexan USUAL ISSUES • Most of the time waiting for

    a request • Maximum capacity • One service can eat up the memory and kill others • Recovery time (2-7h) • Sometimes you have to call your DevOps • It’s stupid to run just one small application • Renting a new server and setup takes > 1h
  11. @simalexan < 5kg Processing machine Different clothes Max weight Can

    be bigger > handles more Can be smaller > more efficient
  12. @simalexan USUAL ISSUES • Mostly waiting for clothes • Maximum

    capacity • One cloth color can spoil the other - my special princess dress • Recovery time (2h - 1 day) • Sometimes you have to call the plumber • Buying a new washing machine and setting it up >2h • Its stupid to wash just one shirt
  13. @simalexan • Mostly waiting for requests • Max capacity •

    One service can eat up the memory and kill others • Recovery time (2-7h) • Sometimes you have to call the DevOps • It’s stupid to run one small service • Renting a new server and setup
 takes > 1h • Mostly waiting for clothes • Max capacity • One cloth color can spoil the other • Recovery time (2h - 1 day) • Sometimes you have to call the Plumber • It’s stupid to wash one shirt • Buying a new washing machine and setup > 1h Can’t be the same?
  14. @simalexan How did the laundry industry evolve? 1934. First “Laundromat”

    1950s Mass Laundromats 1970s 2000s First “Fluff and Fold” Mass “Fluff and Fold” = decline of laundromats
  15. @simalexan Fluff and Fold • Cleaning service with pickup and

    delivery • Pay per item • Can clean 1 or 1000 clothes Disclaimer: The name didn’t originate from 4chan.
  16. @simalexan SERVERLESS •Method of running and deploying software without renting

    or buying a server •Pay per request execution •Can scale services from 1 to 1000
  17. @simalexan HOW DOES IT WORK? A micro isolated environment with

    everything your code needs 
 a plant pot Treats your code as a function Function containers
  18. @simalexan EVENT DRIVEN FUNCTION SCALING function () function () Request!

    Request! Request! Request! Request! Request! Request!
  19. @simalexan Server hosted API structure Login Generate PDF Products Orders

    Send Emails Payment Users Shopping Cart Chatbot Reports Process pictures Register API File storage Database API endpoints
  20. @simalexan Scaling a server hosted API File storage Database Logi

    Gen Pro Ord Sen Pay Use Sho Cha Rep Proc Regi API endpoints Logi Gen Pro Ord Sen Pay Use Sho Cha Rep Proc Regi API endpoints Logi Gen Pro Ord Sen Pay Use Sho Cha Rep Proc Regi API endpoints Logi Gen Pro Ord Sen Pay Use Sho Cha Rep Proc Regi API endpoints
  21. @simalexan Serverless API structure Generate PDF File storage Database API

    Gateway Login Register Orders Users Chatbot Process pictures Shopping Cart Products Payment Reports Send Emails
  22. @simalexan Orders Scaling a serverless API API Gateway Login Register

    Orders Users Chatbot Shopping Cart Products Payment Send Emails Products Products Products Products Orders Some are more used than others! Some are not used at all!
  23. @simalexan PRICING AWS Lambda $0.0000002 PER REQUEST $0.000000834 PER REQUEST

    100ms @ 512MB 1,000,000 REQUESTS PER MONTH FREE NEXT ~ $0.20 TOTAL VARIOUS SIZES PER MILLION
  24. @simalexan PRICING $0.000016 GB-s $0.000000586 PER REQUEST 100ms @ 512MB

    1,000,000 EXECUTIONS PER MONTH FREE NEXT ~ $0.20 TOTAL VARIOUS SIZES PER MILLION Azure Function
  25. @simalexan Deploy? 1. IMPLEMENT FUNCTION 2. UPLOAD ZIP 3. CREATE

    API GATEWAY 5. SET PERMISSIONS 4. SET TRIGGERS
  26. @simalexan Frameworks / Tools? - Amazon SAM - Claudia.js -

    Serverless framework - Amazon CodeStar - Apex
  27. @simalexan Characteristics • Deploy with a single command • Get

    started quickly, flat learning curve • No boilerplate • Use standard NPM modules • Multiple versions very easily
  28. @simalexan ’use strict’ const Api = require(’claudia-api-builder’) const api =

    new Api() api.get(‘/’, () =>”Hello Kharkiv!”) module.exports = api index.js
  29. @simalexan { "lambda": { "role": "kharkivjs-executor", "name": "kharkivjs", "region": "eu-central-1"

    }, "api": { "id": "<lambda-id>", "module": "index", "url": "https://<lambda-id>.execute- api.eu-central-1.amazonaws.com/latest" } } the result
  30. @simalexan - Real time applications with Sockets - Extremely low

    latency apps < 100ms - Long running tasks - Very specific configurations - Need an SLA NOT GOOD FOR
  31. @simalexan GOOD FOR • Web APIs • Micro services •

    Chatbots • IoT • File/Image processing • Rapid prototyping, very quick “time to deploy”
  32. @simalexan REFACTORING • Makes sense as it has a financial

    incentive • Better code, less cost • No more: “Well, its working OK…”
  33. @simalexan CODE EFFICIENCY • Slower code has bigger repercussions. •

    Algorithms having a stronger impact 
 (start reading)
  34. @simalexan SUMMARY • Serverless means no server configuration • Autoscaling

    and autofailover • Function deployment • Effortless with Claudia.js • Event driven • Rapid deployment • Works great with Node.js