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

Migration to Next.js App Router and Best Soluti...

Migration to Next.js App Router and Best Solution Found on K8s

既存のオープンチャットの小さなウェブサービスを統合されたCI/CD環境で管理するために k8s 環境に移行しました。
KubernetesでFEプロジェクトを運営する際に知っておくと良いFE向けのヒントを共有します。
また、既存のクライアントサイドレンダリング (CSR) プロジェクトをNext.jsのApp Routerを使用してサーバーサイドレンダリング (SSR) に移行する際に経験も共有します。

More Decks by LINEヤフーTech (LY Corporation Tech)

Other Decks in Technology

Transcript

  1. Migration to nextjs and best solution we found on kubernetes

    -*/& $POUFOUT4FSWJDF8FC +VOH,ZV4VOH +P+FPOH(FVO
  2. $POUFOUT 01 Best solution we found on Kubernetes - About

    Open Chat - How We Migrated to Kubernetes - Our Kubernetes Architecture Migration to Nextjs App Router - NextJS on Kubernetes - TroubleShooting - What’s Next 02
  3. Jenkins Servers Builder for A service Builder for B service

    Builder for C Service Development Deployment .JHSBUJPOUP,VCFSOFUFT Development C Server B Server A Server Pre-Release Deployment Production Deployment Pre-Release C Server B Server A Server Production C Server B Server A Server
  4. Phase - Phase is suffix for environment - Phase is

    involved with domain Stage - separate and manage the frontend development environment itself, even though it is under the same domain and path - if developer want to deploy two different versions of the main application, it can deploy them as ‘A-Pre-release’ , ‘A-Pre-release2’ .VMUJ5FOBODZ4USBUFHZ "QQMJDBUJPO 1IBTF 4UBHF /BNFTQBDF " 1SFSFMFBTF  "1SFSFMFBTF " 1SFSFMFBTF  "1SFSFMFBTF # %FWFMPQNFOU  #%FWFMPQNFOU # %FWFMPQNFOU  #%FWFMPQNFOU
  5. Production Cluster Production Phase C-Development Development Cluster Development Phase A-Development

    B-Development Pre-Release Phase A-Pre-Release B-Pre-Release C-Pre-Release Stage : 1 .VMUJ5FOBODZ4USBUFHZ Stage : 2 A-Pre-Release2 B-Pre-Release2 A B C
  6. root-app (App of Apps) Helm-based ArgoCD Apps A (Helm Chart)

    B (Helm Chart) C (Helm Chart) Development Cluster A-pre-release A-pre-release2 B-pre-release Pre-release-apps B-pre-release2 Production Cluster A B Production-apps .VMUJ5FOBODZ%FWFMPQNFOU
  7. - CPU resource is compressible resource - Node.JS is single

    thread. - 1.0 core is Best? $163FTPVSDF
  8. - Libuv also utilizes CPU resources, and consequently, requires a

    more generous allocation of CPU resources - 1.15 is acceptable Node.JS V8 Libuv CPU 1.0 $163FTPVSDF $163FRVFTU $16-JNJU 10% 514 ."9514 ."9$166TBHF $PSF1PE  $PSF    
  9. Memory - incompressible resources - Out of Memory Risk -

    In Node.js, for a machine with 2 GiB of memory, it is recommended to allocate 1.5 GiB Memory (requests & limit) Max-old-space-size 1500Mi 1024 2000Mi 1536 .FNPSZ
  10. CPU Limit : Where CPU throttling begins Request : amount

    guaranteed by kubernetes Memory Limit : Level Where process are killed Request : amount guaranteed by kubernetes $16 .FNPSZ3FRVTU-JNJU
  11. - FCP(First Contentful Paint) : when the browser renders the

    first content from the DOM, providing feedback to the user that the page is loading - LCP(Largest Contentful Paint) : the render time of the largest image or text block visible within the viewport, recorded from when the page first begins to load 8IZ/FYU+T
  12. - Applying animations between page transitions using Prefetching - Implementing

    Tab UI using native History API - Server Action Version Skew (Under Investigation) 5SPVCMFTIPPUJOH
  13. Error : Failed to find Server Action `${actionId}`. This request

    might be from older or newer deployment 4FSWFS"DUJPO7FSTJPO4LFX
  14. 1. Create a server action 2. Run next build(actionID :

    00aa~~) 4FSWFS"DUJPO7FSTJPO4LFX
  15. 1. Rename the server action function to getCookie 2. Run

    next build (actionID : 006c~~) The user is still seeing the old version of the Next.js client… getCookie Changed! (00aa => 006c) 4FSWFS"DUJPO7FSTJPO4LFX
  16. What's the reason for this issue? Old Client (id: 00aa~~)

    Old Server (id: 00aa~~) New Server (id: 006c~~) 1. request 2. Roll out 3. request 4FSWFS"DUJPO7FSTJPO4LFX
  17. 1. Retains the previous version of server actions 2. Set

    the NEXT_SERVER_ACTIONS_ENCRYPTION_KEY environment variable 4FSWFS"DUJPO7FSTJPO4LFX
  18. Old Client (id: 00aa~~) Old Server (id: 00aa~~) New Server

    (id: 00aa~~, 006c~~) 1. request 2. Roll out 3. request 4FSWFS"DUJPO7FSTJPO4LFX
  19. Old Client (id: 00aa~~) Old Server (id: 00aa~~) New Server

    (id: 006c~~) New Client (id: 006c~~) GW Check cookie or header Old client’s request New client’s request 4FSWFS"DUJPO7FSTJPO4LFX
  20. NextJS App Router Server Cache 0VS/FYU"DUJPO*OUFHSBUFEJTUSJCVUFEOFYUKTDBDIF Mechanism What Where Purpose

    Duration Request Memoization Return values of functions Server Re-use data in a React Component tree Per-request lifecycle Data Cache Data Server Store data across user requests and deployme nts Persistent (can be revalidated) Full Route Cache HTML and RSC payload Server Reduce rendering cost and improve performan ce Persistent (can be revalidated)
  21. Next Server Next Server Next Server Next Server LB cache

    cache cache cache 0VS/FYU"DUJPO*OUFHSBUFEJTUSJCVUFEOFYUKTDBDIF
  22. Use custom cache solution to integrate distributed cache Next Server

    Next Server Next Server Next Server LB External Store (e.g. redis) 0VS/FYU"DUJPO*OUFHSBUFEJTUSJCVUFEOFYUKTDBDIF