Slide 1

Slide 1 text

Web Application as a Microservice Sota Sugiura Tech Lead (Backend)

Slide 2

Slide 2 text

Tech Lead Backend Sota Sugiura

Slide 3

Slide 3 text

Web Application as a Microservice

Slide 4

Slide 4 text

https://www.mercari.com/jp/

Slide 5

Slide 5 text

JP Web Re-architect

Slide 6

Slide 6 text

Improve scalability of the development team Goals A flexible architecture that is resilient to change 1 2

Slide 7

Slide 7 text

Flexible architecture that is resilient to change ● Keeping up to date with trends ● Scrap and Build

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Improving scalability of the development team ● Architecture that can handle the increasing number of engineers ● Providing freedom for each team to choose their own technology stack

Slide 10

Slide 10 text

Single PHP Server Te m ar Te m ar Box Te m ar G i Now Mercari Mercari Box Mercari Guide

Slide 11

Slide 11 text

SSR GraphQL SPA REST API Simple HTTP server Mic r i s Te m ar Mic r i s Te m ar Box Mic r i s Te m ar G i Goal

Slide 12

Slide 12 text

How to Carry Out the Re-architecture

Slide 13

Slide 13 text

1 Monolithic Service to 4 Microservices

Slide 14

Slide 14 text

Wait, can you migrate all features from a Monolithic Service at once? :P

Slide 15

Slide 15 text

1 Monolithic Service to with 4 Microservices

Slide 16

Slide 16 text

Monolithic Service Feture ・ ・ ・ Monolithic Service Feature ・ ・ ・ Microservice Microservice Microservice Microservice Microservice Microservice

Slide 17

Slide 17 text

Why? ● This is a re-architecture, not a redesign ● Limiting the scope of migration at first ● We will start by taking on many small challenges and failures

Slide 18

Slide 18 text

Limiting the migration scope

Slide 19

Slide 19 text

Monolithic Service Feature ・ ・ ・ /jp/*

Slide 20

Slide 20 text

Monolithic Service Feature ・ ・ ・ Microservice Microservice /jp/* /jp/top

Slide 21

Slide 21 text

How we decided the order of migration ● Difficulty ● Clashes with other tasks and changes ● Amount of traffic

Slide 22

Slide 22 text

Challenges

Slide 23

Slide 23 text

Challenges Monolithic Service + Microservices 1 2 Separating Frontend and Backend 3 Session synchronization

Slide 24

Slide 24 text

GraphQL SSR mercari-web mercari-api Web Gateway Session service CDN

Slide 25

Slide 25 text

GraphQL SSR mercari-web mercari-api Web Gateway Session service CDN 1 2 3

Slide 26

Slide 26 text

GraphQL SSR mercari-web mercari-api Web Gateway Session service CDN 1 2 3

Slide 27

Slide 27 text

Web Gateway ● Balancing for each service ● Initially for both new and old architectures to co-exist ● In the future, for Web Microservices

Slide 28

Slide 28 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others CDN

Slide 29

Slide 29 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others CDN /hoge=”Service A” /moge=”Service B”

Slide 30

Slide 30 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 0% 100% WI

Slide 31

Slide 31 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 10% 90% WI

Slide 32

Slide 32 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 100% 0% WI

Slide 33

Slide 33 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 10% 90% A B WI

Slide 34

Slide 34 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 10% 90% A B WI

Slide 35

Slide 35 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 10% 90% A B WI

Slide 36

Slide 36 text

● Mapping with path control ● Scoped release ● Session persistence Web Gateway mercari-web Service A Service B /hoge /moge /others 10% 90% A B WI

Slide 37

Slide 37 text

GraphQL SSR mercari-web mercari-api Web Gateway Session service CDN 1 2 3

Slide 38

Slide 38 text

How is frontend affected by the backend migration to Microservices?

Slide 39

Slide 39 text

mercari-web mercari-api JSON over HTTPs

Slide 40

Slide 40 text

mercari-web mercari-api JSON over HTTPs SSR JSON over HTTPs New!

Slide 41

Slide 41 text

mercari-web mercari-api JSON over HTTPs SSR Offer service JSON over HTTPs gRPC New!

Slide 42

Slide 42 text

mercari-web mercari-api JSON over HTTPs SSR Offer service JSON over HTTPs gRPC Listing service gRPC New!

Slide 43

Slide 43 text

mercari-web mercari-api JSON over HTTPs SSR Offer service JSON over HTTPs gRPC Listing service gRPC New! Buying service New! Live service New! User service

Slide 44

Slide 44 text

mercari-web mercari-api JSON over HTTPs SSR Offer service JSON over HTTPs gRPC Listing service gRPC New! Buying service New! Live service New! User service ● We need to keep up to date with the specs for every new microservice ● We need to write high-performance code

Slide 45

Slide 45 text

mercari-web mercari-api JSON over HTTPs BFF Listing Service JSON over HTTPs gRPC Offer Service gRPC Our strategy SSR

Slide 46

Slide 46 text

mercari-web mercari-api JSON over HTTPs BFF Listing Service JSON over HTTPs gRPC Offer Service gRPC Our strategy SSR Frontend Engineer Backend Engineer

Slide 47

Slide 47 text

Backends for Frontends in our JP Web Re-architecture ● Our definition of BFF: “a layer to aggregate backend microservices” ● To improve the development experience for frontend engineers

Slide 48

Slide 48 text

What to implement as BFF ● GraphQL - works well with SPAs ● a

Slide 49

Slide 49 text

GraphQL SSR mercari-web mercari-api Web Gateway Session service CDN 1 2 3

Slide 50

Slide 50 text

Session synchronization issues ● Several microservices will exist in the same domain ● Need to maintain consistency with the longin state of the Monolithic Service

Slide 51

Slide 51 text

mercari-web Logged-out user SSR server

Slide 52

Slide 52 text

mercari-web POST /login SSR server Logged-out user

Slide 53

Slide 53 text

mercari-web Logged-in user Success! SSR server

Slide 54

Slide 54 text

mercari-web Logged-in user GET / SSR server

Slide 55

Slide 55 text

mercari-web Should show page for logged in users SSR server Logged-in user

Slide 56

Slide 56 text

Microservice for managing session ● Create a microservice to manage sessions ● Maintaining session consistency and data preservation, etc. ● Assume multiple microservices will use this

Slide 57

Slide 57 text

How we will manage synchronization

Slide 58

Slide 58 text

mercari-web Session service Request Call to get session every time Response Session data SSR server

Slide 59

Slide 59 text

mercari-web Session service Request Call to get session every time Response Session data SSR server

Slide 60

Slide 60 text

https://gist.github.com/jboner/2841832 Latency Numbers Every Programmer Should Know

Slide 61

Slide 61 text

mercari-web Session service Q. What’s the distance here? SSR server

Slide 62

Slide 62 text

About 800km ※だいたいです

Slide 63

Slide 63 text

Data transmission between Hokkaido and Tokyo ● We use GKE in Tokyo region ● The exisiting Monolithic Service will run from Hokkaido ● We need to design the architecture with latency in mind

Slide 64

Slide 64 text

● Making Storage to  store cache data ● Minimize amount of back-and-forth data transmission in Japan mercari-web Session service New! Cache storage

Slide 65

Slide 65 text

mercari-web Session service New! Cache storage ● We chose gRPC via Node.js ● Based on technical expertise of our members

Slide 66

Slide 66 text

mercari-web Session service mercari-api Cache storage SSR server

Slide 67

Slide 67 text

mercari-web Session service mercari-api Cache storage Firstly, check the Cache and DB at hand to check for existing session data SSR server

Slide 68

Slide 68 text

mercari-web Session service mercari-api Cache storage If no session data can be found, check for the session in Monolithic Service SSR server

Slide 69

Slide 69 text

mercari-web Session service mercari-api Cache storage With the session data, request authentication data to the Monolithic API SSR server

Slide 70

Slide 70 text

mercari-web Session service mercari-api Cache storage Save session data SSR server

Slide 71

Slide 71 text

● Use cache data if it exists, but if not, get from Hokkaido ● No access to Tokyo from Hokkaido ● This ensures security and consistency Simple is the best!

Slide 72

Slide 72 text

Conclusion

Slide 73

Slide 73 text

Sowing the seeds of success ● Implement a supreme architecture ● Make it possible to develop at explosive speeds ● And provide the ultimate developer experience

Slide 74

Slide 74 text

So many challenges! ● Tech stack ● Re-architecture ● Evolving and scaling our development structure

Slide 75

Slide 75 text

Al or One All for the ultimate Web

Slide 76

Slide 76 text

Thank you :) Feel free to ask me any questions at the “Ask the speaker” booth

Slide 77

Slide 77 text

No content