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

Techniques for Building Disruptive Software For...

Shuaib Afegbua
November 13, 2018
140

Techniques for Building Disruptive Software For a Concurrent World

How do you build for Scale? How about if you could write software that can run forever, survive crashes and self-heal? A software that is always online without downtime and provides service to their clients even when faced with unexpected circumstances.

Why you should care: we are in a highly connected age of internet of things with multiple connected devices, social networks, multiplayer games, high traffic web servers etc. To meet the demand and to always provide uninterrupted services to user, regardless of unexpected bugs, hardware or software failures, Software systems have to resilient and highly available

Shuaib Afegbua

November 13, 2018
Tweet

Transcript

  1. eNigeria 2018 Masterclass Session Shuaib Afegbua |> @afegbuas LET IT

    CRASH: TECHNIQUES FOR BUILDING DISRUPTIVE SOFTWARE For a Concurrent World
  2. My past, present and possible future • Computer Science major

    (FUTMINNA and ABU) • Worked at Mott Macdonald/Cambridge Education for a long time and some other places • Got tired, quit and stayed at home. @afegbuas
  3. My past, present and possible future • Got bored and

    started #buildingTheFuture (what the hell is that?) at ECTORIUM • I love building things - comvers, spaces.ng, powershop.ng and some others I can’t list here • Amateur writer • I have an addiction bleeding edge technology • Got another addiction - READING @afegbuas
  4. An MVP Something you can ship out to user. A

    Minimum Valuable, Viable, Validating, Product.
  5. Launch & Feedback You test the market and get feedback

    from users, sometimes cruel responses
  6. @afegbuas 60 billion Whatsapp messages Over 2.5 quintillion bytes of

    data daily (2.5 x 1018 or 2 trillion million) => 10 million blu-ray disc 24/7 connected systems Social networks Web servers Multi players game
  7. What becomes imperative? “The system must be responsive, regardless of

    the number of connected clients. The impact of unexpected errors must be as minimal as possible, instead of affecting the entire system. It’s acceptable if an occasional request fails due to a bug, but it’s a major problem when the entire system becomes completely unavailable. Ideally, the system should never crash or be taken down, not even during a software upgrade. It should always be up and running, providing the service to its clients.” ... SAS ̌ A JURIC ́
  8. What is a highly available system A software that is

    always online without downtime and provides service to their clients even when faced with unexpected circumstances. Hence it has to be fault tolerant, scalable, responsive and distributed. @afegbuas
  9. Fault tolerance • A system has to keep working when

    something unforeseen happens. • Minimise, isolate, and recover from the runtime errors effects to keep the system up @afegbuas
  10. Responsiveness • System reasonably fast and responsive • No prolonged

    request handling, even if the load increases or unexpected errors happen • Lengthy tasks shouldn’t block the rest of the system or have a significant effect on performance. @afegbuas
  11. WhatsApp • 55 Billion messages per day • 35 engineers

    at 450M user, 50 at 900M users • 1 Billion active daily users • 1.3 billion active monthly users • 1 billion videos per day • 4.5 Billion photos per day • 60 supported languages
  12. BleacherReport • World 2nd largest sports website, gets 1.5 billion

    page views per month and 250,000 users at its peak • Initially on Ruby on Rails, but later, they experienced issues with scaling. • They moved from 150 to 5 AWS servers. • From 50 engineers to 15
  13. Pinterest • 250 million monthly active users as of October

    2018 • Rewrote their api: 50 percent response time is around 500 microseconds with a 90 percent response time of 800 microseconds., microseconds! • 90% reduction in lines of code 10,000 to 1000
  14. Moz • An analytic company that helps clients to be

    more visible in search engines • They adopted Elixir to create a database-free solution for analytics That became faster than the database solution
  15. BET 365 • They handle over 6 million HTTP requests

    and more than 500,000 database transactions per second! • They deliver live online experiences in 17 languages to over 11 million customers worldwide.
  16. CDFIPB Recruitment • You all know tales from online recruitment

    in Nigeria • 41K concurrent users at peak period. An average of 1K users on low period • We had two commodity servers hosted on linode
  17. Aeternity • A blockchain company • Need to scale their

    distributed system and peer-to-peer network by providing fault tolerant systems capable of scaling to billions of potential users.
  18. Concurrency Many things happening at a time Parallelism Two or

    more things happening simultaneously @afegbuas
  19. Shared memory concurrency • Components communicate by altering content of

    memory locations. • Mainly handled by the OS • Uses locks to to communicate between threads • C#, Java, C, C++, .
  20. Message based concurrency • Communicate by sharing messages between processes

    (Actors) • A process is an independent and usually different from OS process • Erlang, Elixir, LFE, Akka (Scala and Java), Dart, occam.
  21. Erlang Erlang is platform for building highly available systems. It

    consisting of four distinct parts: • the language, • the virtual machine, • the framework • the tools.
  22. How Erlang? A little bit of story of the tortoise

    fell from heaven and cracked it shell Conceived by Ericsson team led by Joe Armstrong, in the 80s to solve their telecom needs Sas Juric: “A telephone network should always operate regardless of the number of simultaneous calls, unexpected bugs, or hardware and software upgrades taking place.” @afegbuas
  23. Design goal To provide 99.9999999% availability = 1 second downtime

    every 32 years Erlang is sometimes called a concurrency-oriented language.. • Compiled • Immutable state • Functional paradigm • Abstracted Processes • Message based concurrency • Supervision tools • Distributed @afegbuas
  24. Process • The process is the basic unit of concurrency

    • Lightweight and cheap - about 1kb/2kb initial memory footprint. Can grow and shrink as required • No shared state/memory thus never need to compete for locks for access to shared data. • They communicate by sending messages. The receiver gets a read only copy of the sender’s message (transparent distribution)
  25. ERLANG VM (BEAM) A single operating system process SCHEDULER THREAD

    CPU Image credits: https://pragmaticstudio.com/
  26. Fault Tolerance • Erlang processes are completely isolated from each

    other • They crash alone • Supervisors are present to detects and manage failures
  27. Distribution • Erlang processes are completely isolated from each other

    • They crash alone • They communicate by sending messages. The receiver gets a read only copy of the sender’s message (transparent distribution)
  28. Scalability • No shared state/memory thus never need to compete

    for locks for access to shared data. • No locks, mutexes, or semaphores • Erlang processes are completely isolated from each other • The virtual machine can efficiently parallelize the execution of processes as much as possible • Erlang programs take advantage of all available cores to execute programs
  29. Distribution • Same mode of communication regardless of the machine

    where the process is running be it single or remote machine; local and remote • Handles failures across machines
  30. Responsiveness • Excellent scheduler preemption • I/0 operations are delegated

    to separate threads internally • Excellent garbage collection
  31. Erlang code can be difficult and verbose So you can

    write nicer erlang: Elixir @afegbuas
  32. Elixir Elixir is a dynamic, functional language designed for building

    scalable and maintainable applications and runs on the Erlang virtual machine (BEAM). @afegbuas
  33. Elixir ? All the goods of Erlang plus • Concise

    - Erlang is verbose • Metaprogramming with Macros. • Polymorphism using Protocols • Better tools - mix and hex • Friendlier syntax • Seamless interoperability @afegbuas
  34. Abstracting process Agents and Task • Start a process •

    A recursive function in an infinite loop passing the state for each function call • A way to handle message • How to respond to these messages @afegbuas
  35. OTP behaviours GenServer • Generic Server behaviour is an abstraction

    of client/server functionality GenEvent • A behaviour module that Provides event-handling support Supervisor • Provides error handling and recovery in concurrent systems Application • Generic implementation of components and libraries @afegbuas
  36. So what next? • Build fast and build well •

    Think design, test fast and iterate. • Adopt the right tools. • Create appealing user experience • Create a knowledge base company • Avoid over bloated engineering team. Recruit for your need