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

Backend For Frontend: The Missing Manual at Dev...

Backend For Frontend: The Missing Manual at Devoxx Ukraine

Nikita Galkin

November 01, 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. 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
  6. 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
  7. 39 ▰ http2 and gzip ▰ For REST use ETag

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

  9. 41

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

    server <-> client • client Subscription • server Updates
  11. 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
  12. • 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
  13. ➜ ~ 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>)
  14. 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
  15. ▰ Faster Development ▰ Save your colleagues time ▰ Move

    Border Between Client and Server ▰ Provide WebApi Specification ▰ Control Small Response Time