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

Scalable, Low Cost and Decoupled Push Notification Architecture with AWS @ MelbourneCocoaheads

Scalable, Low Cost and Decoupled Push Notification Architecture with AWS @ MelbourneCocoaheads

Krutarth Majithiya

December 08, 2016
Tweet

Other Decks in Programming

Transcript

  1. PUSH NOTIFICATION SERVICE DECOUPLED, SCALABLE, CHEAP & ALSO IN-HOUSE By

    Krutarth Majithiya (Kru) iOS Developer @ Sportsbet @krutosh 1 Million Push Notification under $20 USD / Month
  2. NOTE Apology for the amazon web services related jargon. This

    is an attempt to build a cheap backend architecture as part of my small start up. I might have missed important things. So, please point it out, I will be happy to learn something new today
  3. MY FIRST TASK CREATE OUR OWN PUSH NOTIFICATION SERVICE Available

    Scalable Easy to Access Secure Low Cost It needs to support Millions of Pushes a Month
  4. OPTION 1 Available ✅ Scalable ✅ Easy Access ❌ Secure

    ❌ Low Cost ✅❌ Redundancy Very High Web Servers API Servers Database APNS GCM APNS CERTS GCM Server API Key APNS CERTS GCM Server API Key
  5. OPTION 2 Available ✅ Scalable ✅ Easy Access ❌ Secure

    ✅❌ Low Cost ✅❌ Redundancy High Web Servers API Servers Database Simple Notification Service APNS CERTS GCM Server API Key IAM ROLE IAM ROLE
  6. OPTION 3 Available ❌❌❌❌❌ Scalable ❌❌❌❌❌ Easy Access ✅ Secure

    ✅ Low Cost ❌ Redundancy High Web Servers API Servers Database Push Server Simple Notification Service APNS CERTS GCM Server API Key IAM ROLE https://api.pushservice.com /push? data=something &target=TargetARN https://api.pushservice.com /push? data=something &target=TargetARN
  7. OPTION 4 Available ✅ Scalable ✅ Easy Access ✅ Secure

    ✅ Low Cost ❌❌❌❌❌ Redundancy High Web Servers API Servers Database Push Servers AZ1 - AZ2 Elastic Load Balancer Simple Notification Service APNS CERTS GCM Server API Key IAM ROLE https://api.pushservice.com /push? data=something &target=TargetARN https://api.pushservice.com /push? data=something &target=TargetARN
  8. Let’s choose those paid services or go with those freemiums

    who sell our push data to third-party. @image_courtasy: Chris Martinié
  9. OPTION 5 Web Servers API Servers Database Available ✅ Scalable

    ✅ Easy Access ✅ Secure ✅❌❌❌ Low Cost ❌❌❌❌❌ ❌❌ Redundancy Very High Many Others https://api.someservice.com /push? data=something &token=deviceToken &apiKey=Foo https://api.someservice.com /push? data=something &token=deviceToken &apiKey=Foo APNS CERTS GCM Server API Key
  10. CHECK LIST • I want push notifications to be triggered

    from anywhere possible, in short wherever there is a business process. • I want to treat single push notification as a piece of work, Which needs to get processed by a computer, either EC2 or may be a Lambda function. • I want to asynchronously process all the errors coming back from APNS and GCM and deal with them individually when I have resource in idle mode. • I want to scale to the edge of the universe ! • I want it dirt cheap!
  11. Web Servers Database API Servers Any Service which can upload

    a file to S3 DBLambda PushDataBucket OtherServices Lambda S3EventTriggered Lambda SNS APNS GCM SNSTriggeredErrorHandler OPTION 6 Available ✅ Scalable ✅ Easy Access ✅ Secure ✅ Low Cost ✅ Redundancy Medium APNS CERTS GCM Server API Key
  12. HOW DOES IT WORK? PushDataBucket S3EventTriggered Lambda SNS • JSON

    file added Into the 
 Bucket • Lambda function extracts data
 and Target ARN or Topic ARN • Lambda function sends request 
 to SNS Bucket PUT Event
  13. FACTS ABOUT S3 • Amazon S3 bucket routinely exceeds 100

    PUT/ LIST/DELETE requests per second • Amazon S3 scales to support very high request rates. If your request rate grows steadily, Amazon S3 automatically partitions your buckets as needed to support higher request rates.
  14. SIMPLE MATH With Option 6, theoretically we can send a

    whopping 100*(24*60*60) = 8,640,000 pushes per day! Our aim is to test sending, 12*(24*60*60) = 1,036,800 pushes per day! We wanted to support only a million per month. above is just for test.
  15. CONCLUSION • We sent 200,000+ notification to a single device

    without losing single push, or receiving redundant pushes. • It costed us about $0.04 USD • Based on AWS calculator, if we send a million push with S3 and Lambda architecture it will cost us approx., • S3 = $6.44 USD • Lambda = $4.37 USD • So, with about $10.81 USD / Month you can send a million pushes. Add other $9.91 to support processing failed pushes etc.