Modular Fronted Architecture With ROCA¶

About Me¶

Gaurav Sehrawat¶

Global Solutions Architect/Tech Lead @Verifone¶

🌎: Website: https://igauravsehrawat.com/¶

🧑‍💻Github: https://github.com/igauravsehrawat¶

🕊Twitter: https://twitter.com/Root3d¶

🤝 LinkedIn: https://linkedin.com/in/igauravsehrawat¶

Agenda¶

  • What is Architecture And Why care for it?
  • Different Frontend Architecture?
  • Modular Vs Monolith Frontend?
  • How to Integrate Modular Frontend?
  • Client Side Integration
  • Edge Side Integration (Cache/CDN)
  • Server Side Integration
  • Recap
  • Questions?

ROCA QR Code

In [ ]:

In [14]:
Notes:
    Tell the problem and then deep dive into solution
    Too many slides
    Why you
    One of the paradigm

    Why
    Remove the SCS

    Problem and challenges
    Solution should take more time
    Time management issue
    Explain the solution more


Template
about me
problem
And the solution.......
  File "<ipython-input-14-db5ba5d18387>", line 1
    Notes:
          ^
SyntaxError: invalid syntax

A Step Back¶

What is Architecture?¶

The decisions you wish you could get right early in a project.¶

Defines notion of the most important aspects of the internal design of a software system.¶

https://martinfowler.com/architecture/

Talk is indepedent of framework, technology or tooling¶

Why This Talk?¶

  • It's just a different paradigm to be aware of
  • It won't solve all the problems you have
  • But it might solve few

Why Do We Need A Good Architecture?¶

Jackie Chan GIF

Problem statement?¶

We Need Speed¶

Looking for speed

Time To Deliver To Market¶

Time To Deliver To Browser¶

Time To Render In Browser¶

Quality And Cost To Deliver¶

cost to market

  • Source https://martinfowler.com/architecture/

What All Can Be There?¶

Frontend Monolith¶

Frontend Monolith

Frontend Self Contained Service¶

frontend scs

Frontend Modules/Micro¶

Frontend microservice

Frontend Monolith vs Modular¶

Why Monolith?¶

  • If one team is required
  • Project is not big
  • SPA apps
  • It will save efforts of dividing into microservices

Why Modular?¶

  • If multiple teams can work on same UI
  • Can be broken down into concerning domain logic
  • Change in domain can be implemented by modifying and deploying just one service

Which Architecture Is Better Suited For Frontend Integration?¶

Presenting You....¶

presenting-you-roca

ROCA (Resource Oriented Client Architecture)¶

  • Set of recommmendation for frontend modularization and integration

Benefits¶

  • Loose coupling
  • Logic and UI in one microservice/domain
  • Free choice of frontend technology

Let's say you did the modularized your Frontend with¶

  • Self Contained Services
  • Micro-Frontend
  • Or Anyhow 😄

How To Do Frontend Integration¶

  • Client Side Integration
  • Server Side Integraiton

Client Side Integration¶

Via Links¶

  • Just Hyperlink one to another (Nothing special)

Via Redirects¶

  • Links but with data is redirects
    • e.g OAuth, when signining up with third-parties

Transclusion¶

  • Combining content of website into another website
  • Will see later
  • Credits: educative.io

ROCA Principles¶

  • REST based
  • Accessible, not just html, json,
  • Logic on the server, Javascript for UI purpose only
  • HTTP authentication on server
  • Cookies for tracking and authentication, not for business logic
  • No layout info int HTML, CSS should be separate
  • No redundant logic on frontend

Notes: If you need to change the website it's better to redesign the UI first rather than modularising it

Notes: if links are used for integration, only the URL has to be known for integration to occur if todo list and UI needs to be changed, only one microservice will do it each microservice has it's own frontend that can use it's own technology for e.g, angular -> react -> vue.js (each teeam, how-so ever it evolves)

Integration (Demo Time )¶

Demo Time

Links And Client Side Integration¶

  • Case study of https://crimson-portal.herokuapp.com/ from INNOQ case study crimson
  • Credits INNOQ

for the main application (https://crimson-portal.herokuapp.com/) for reporting damages (damage application) (https://crimson-damage.herokuapp.com/) for writing letters (letter application) (https://crimson-letter.herokuapp.com/) for the postbox (postbox application)(https://crimson-postbox.herokuapp.com/).

Integration with Redirects¶

    Show example for redirect

Integration With Javascript As Transclusion¶

transclusion

  • Credits: Educative
<a href="https://crimson-postbox.herokuapp.com/m50000/messages"
  class="preview" data-preview="enabled"
  data-preview-title="Notifications"
  data-preview-selector="table.messages-overview"
  data-preview-error-msg="Postbox unreachable!"
  data-preview-count="tbody>tr" data-preview-window>
  • Case study of https://crimson-portal.herokuapp.com/ from INNOQ

  • From common styleguide component

https://github.com/ewolff/crimson-styleguide/tree/master/components/preview

Render The Content Of The Link¶

$(document).ready(function() {
  $("a.embeddable").each(function(i, link) {
    $("<div />").load(link.href, function(data, status, xhr) {
      $(link).replaceWith(this);
    });
  });
});

Other Integration Method¶

Iframe¶

Embed¶

Object¶

  • More Info Here: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding
  • Above code replaces the link with the content of the link, like whole html is displayed

Server Side Integration¶

Edge Side Includes - ESI¶

  • It's a language https://www.w3.org/TR/esi-lang
  • assemble resources in HTTP clients.
  • CDN/Cache implements ESI
  • improve end-user perceived performance, reduce processing overhead on the origin server, and enhanced availability

How Do We Implement?¶

Varnish¶

Varnish is mainly used for optimizing web servers:

  • It intercepts the HTTP requests to web servers.
  • Manipulate ESI
  • It then caches the responses.
  • It forwards only those requests to the web servers that are not in the cache.

  • More About Varnish: https://book.varnish-software.com/4.0/chapters/Introduction.html

Sample ESI¶

<html>
<head>
  ...
  <esi:include src="/common/header"></esi:include>
</head>

<body>
  <div class="container">
    <esi:include src="/common/navbar"></esi:include>
    ...
  </div>
  <esi:include src="/common/footer"></esi:include>
</body>
</html>

In this example, the attempt is to fetch an ad. If the ad fetch fails, a static link will be included instead.¶

<esi:try>
    <esi:attempt>
        <esi:comment text="Include an ad"/>
        <esi:include src="http://www.example.com/ad1.html"/>
    </esi:attempt>
    <esi:except>
        <esi:comment text="Just write some HTML instead"/>
        <a href=www.akamai.com>www.example.com</a>
    </esi:except>
</esi:try>

An Example Of Varnish Configuration¶

vcl 4.0;

backend default {
    .host = "order";
    .port = "8080";
}

backend common {
    .host = "common";
    .port = "8180";
}

sub vcl_recv vcl_recv {
    if (req.url ~ "^/common") {
       set req.backend_hint = common;
    }
}

sub vcl_backend_response{
    set beresp.do_esi = true;
    set beresp.ttl = 30s;
    set beresp.grace = 15m;
}

Case Study example here: https://github.com/ewolff/SCS-ESI

  • Credits Educative
In [ ]:
# BreakDown of Previous Slide

Notes:¶

  • Version ofcourse
  • Two backend directives/vars
  • Notice the host and port are currently docker from the case study
  • /common => goes to common (which has bootstrap and headers)
  • interpret ESI
  • cache 30s
  • if server goes down, show cache pages for 15 minutes

Also Server Side Integration (SSI)¶

Zolando Architecture (Mosiac)¶

Zolando Architecture

Tailor¶

  • Tailor is a layout service that brings microservices to the frontend by composing a website out of various Fragments (such as Header, Product, and Footer).

  • Tailor achieves impressive Time to First Byte, as it asynchronously fetches multiple fragments, assembles their response streams, and outputs the final response.

An example of SSI¶

# custom log format
log_format timed_combined '[$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    'ReqTime: $request_time UpstreamTime: $upstream_response_time $pipe';

access_log /var/log/nginx/scs-commerce.dev.access.log timed_combined;

upstream landing-page {
 server landing-page:3000;
}

upstream products {
 server products:3001;
}

upstream order {
 server order:3002;
}

upstream assets {
 server assets:3003;
}

proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";

server {
  listen 80;
  server_name scs-commerce.dev;
  ssi on;
  ssi_silent_errors off;

  # set $some_var "...";

  location / {
    proxy_pass  http://landing-page/;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;

    proxy_pass_header Set-Cookie;
  }

  location /products/ {
    proxy_pass  http://products/;
    proxy_redirect off;
    proxy_set_header Host $host:$server_port$uri;

    # proxy_cache my_zone;
    # proxy_cache_valid 200 1M;
    # proxy_ignore_headers Expires Cache-Control Set-Cookie;
    # add_header X-Proxy-Cache $upstream_cache_status;
  }

  location /order/ {
    proxy_pass  http://order/;
    proxy_redirect off;
    proxy_set_header Host $host:$request_uri;

    proxy_pass_header Cookie;
  }

  location /assets/ {
    proxy_pass  http://assets/;
    proxy_redirect off;
    proxy_set_header Host $host:$server_port$uri;
  }
}

COMPONENTS

Tailor https://github.com/zalando/tailor Tailor is a layout service that brings microservices to the frontend by composing a website out of various Fragments (such as Header, Product, and Footer). Tailor achieves impressive Time to First Byte, as it asynchronously fetches multiple fragments, assembles their response streams, and outputs the final response. Tailor is partially inspired by Facebook’s BigPipe.

Skipper https://github.com/zalando/skipper Skipper is an extendable HTTP router for service composition. It's built on top a reverse proxy with the ability to select routes based on predicates, and to modify requests and responses with filters. It can be useful for all teams who are trying to deploy a microservices architecture and want (or need) to decouple routing from service logic.

Shaker Shaker is a library and living showcase for UI components. It is used inside Zalando to provide a consistent user experience while developing Fragments in distributed and autonomous teams.

Quilt Quilt is the template storage used by Tailor. It integrates with Zalando's team structure and provides a REST API that allows multiple development teams to manage their templates.

Innkeeper https://github.com/zalando/innkeeper Innkeeper is a RESTful API that stores routes, so that they can be fetched by Skipper. Innkeeper can export the routes in the eskip format. As routes are divided by paths, it allows multiple teams to manage their individual paths. It is developed in Scala.

Tessellate https://github.com/zalando-incubator/tessellate Tessellate is a server-side React renderer that creates static HTML and a complementary component tree from abstract JSON definitions. It comprises several micro services built on top of the Mosaic architecture.

Learn More about Mosaic¶

  • https://www.mosaic9.org/

Benefits of ROCA¶

  • Clean Architecture
  • Browers optimization can be exploited
  • HTTP GET can be cached
  • Low Bandwith
  • High speed
  • High resilence

ROCA vs SPA

  • SPA allows redudant logic on frontend
  • SPA is better suited for complex UIs

ROCA is good frontend integration technique for microservices based architecture

Challenges¶

  • UI Infrastructure
  • Uniform look and feel
  • Interfaces in Frontend Integration
  • UI changes impact mutliple module

Again Why Do We Need A Good Architecture?¶

Jackie Chan GIF

Predict the Future¶

cost to market

  • Source https://martinfowler.com/architecture/

Thank You For Joining¶

Questions?¶

Thank you

About Me¶

Gaurav Sehrawat¶

Global Solutions Architect/Tech Lead @Verifone¶

🌎: Website: https://igauravsehrawat.com/¶

🧑‍💻Github: https://github.com/igauravsehrawat¶

🕊Twitter: https://twitter.com/Root3d¶

🤝 LinkedIn: https://linkedin.com/in/igauravsehrawat¶