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

Backend For Frontend: The Missing Manual

Backend For Frontend: The Missing Manual

Nikita Galkin

August 10, 2019
Tweet

More Decks by Nikita Galkin

Other Decks in Programming

Transcript

  1. Nikita Galkin Love and Know: ▰ How to make developers

    and business happy ▰ Technical and process debt elimination Believe that: ▰ Any problem must be solved at the right level ▰ Software is easy. People are hard ▰ A problem should be highlighted, an idea should be "sold", a solution should be demonstrated Links: Site GitHub Twitter Facebook 2
  2. ▰ Browser API as Desktop API. Chrome Experiments ▰ Business

    wants a feature faster ▰ Frontend Frameworks evolving . RealWorld Examples
  3. Additional requirements: ▰ UX/UI ▰ Adaptive design ▰ SEO ▰

    Accessibility ▰ JAMstack (ex: GatsbyJS) ▰ Progressive Web Applications ▰ Performance
  4. Netflix Technology Blog, Jul 9, 2012 ▰ ✋✋✋ one-size-fits-all (OSFA)

    REST API ▰ Embrace the Differences of the Devices ▰ Separate Content Gathering from Content Formatting/Delivery ▰ Redefine the Border Between Client and Server
  5. Tools: ▰ Amazon API Gateway ▰ Google Cloud Apigee ▰

    Microsoft Azure API Management ▰ Kong ▰ Tyk ▰ etc
  6. Netflix Technology Blog, Jul 9, 2012 ▰ ✋✋✋ one-size-fits-all (OSFA)

    REST API ▰ Embrace the Differences of the Devices ▰ Separate Content Gathering from Content Formatting/Delivery ▰ Redefine the Border Between Client and Server
  7. Design APIs before development! Design APIs in a format that's

    readable for machines. For example: ▰ Swagger for REST ▰ AsyncAPI for WS ▰ gRPC or JSON-RPC for RPC ▰ GraphQL for batch and spec from the box
  8. 43 ▰ http2 and gzip ▰ For REST use ETag

    for browser cache and optimistic locking ▰ Precomputed data is better than cache ▰ Log and analyze long requests
  9. 44

  10. 45

  11. REST • client -> server • Initial state WebSocket: •

    server <-> client • client Subscription • server Updates
  12. Server Side Events • EventSource at browser • Stream at

    BackEnd • Only text data • Reconnect from the box with last message id • Events and retry from server • http2 required for many connections • Awesome for fintech projects
  13. • Object serialization ◦ BigNumber example ◦ Date to timestamp

    or string? • JSON doesn’t support binary data, so use multipart/form-data or base64 • Client can request different content type. Use Accept header • Compare binary size (protobuf, etc) only with gzip/brotli
  14. ➜ ~ node -v v10.16.0 ➜ ~ node > const

    b = 15346349309n; undefined > b*b 235510437113844777481n > Number(b) * Number(b) 235510437113844800000 > JSON.stringify(b) Thrown: TypeError: Do not know how to serialize a BigInt at JSON.stringify (<anonymous>)
  15. REST Example: • Consistency • Pagination: skip=10&take=10 • Order: order[name]=ASC&order[date]=DESC

    • Fields: fields[name]&fields[date] • Singular VS Collection ◦ Entity ◦ Entity Array+Aggregations
  16. ▰ Faster Development ▰ Save your colleagues time ▰ Move

    Border Between Client and Server ▰ Provide WebApi Specification ▰ Control Small Response Time
  17. HAPPY BACKEND DEVELOPMENT! You can find me on Twitter as

    @galk_in Slides are available at speakerdeck.com/galkin or at my site galk.in