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

Improving Demae-can Home Maintainability with Large-Scale Refactoring

Improving Demae-can Home Maintainability with Large-Scale Refactoring

Tomokazu Kudo (Demae-can / Product Division / Commerce Development Department / Application Development Group / Software Engineer)

https://tech-verse.me/ja/sessions/112
https://tech-verse.me/en/sessions/112
https://tech-verse.me/ko/sessions/112

Tech-Verse2022

November 18, 2022
Tweet

More Decks by Tech-Verse2022

Other Decks in Technology

Transcript

  1. Tomokazu Kudo - Android Engineer - 2016.04 ~ 2021.03 -

    Android Mobile App - Android Embedded System - 2021.04 ~ - Demae-can App - Learning React / React Native - Favorite Programing Language - Kotlin / TypeScript
  2. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  3. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  4. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  5. 2021.4~ 2020.3 Capital business partnership 2020.5 First app developer joined

    Demae-can Refactoring background: History We joined Demae-can app team
  6. Refactoring background: Software product quality Maintainability - No specification document

    - Complicated logic - No testing code - State Management • Search options • Delivery address (Block-code) • Standard or Schedule delivery
  7. Usability - Need to wait all API responses to render

    the page - Time to render the page - Need to reload the all components when a state is changed Maintainability Refactoring background: Software product quality - No specification document - Complicated logic - No testing code - State Management • Search options • Delivery address (Block-code) • Standard or Schedule delivery
  8. Update food category UI component Update delivery address info header

    component Implement universal links and AppLinks Free shipping campaign Integrate new Ads API with the page Recommend shops feature UI, UX PJ Business PJ Refactoring background: Software product quality Maintainability Usability
  9. Free shipping campaign UI, UX PJ Business PJ Refactoring background:

    Software product quality Maintainability Usability
  10. Implement universal links and AppLinks UI, UX PJ Business PJ

    Refactoring background: Software product quality Maintainability Usability
  11. Update food category UI component Update delivery address info header

    component Implement universal links and AppLinks Free shipping campaign Integrate new Ads API with the page Recommend shops feature UI, UX PJ Business PJ Refactoring background: Software product quality Maintainability Usability Can we handle bigger PJs?
  12. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  13. Problem of the shop list screen: Summary Data flow Legacy

    React architecture • Huge response from an API • API response delay • Legacy class component implementation Data fetching • Complex data flow
  14. Shop List Screen APP Shop list Recommend Order history Banner

    API Problem of the shop list screen: Data fetching
  15. The number of merchants Ex.) 1500 shops 2.9 MB 800

    msec • API response delay • Huge data set Problem of the shop list screen: Data fetching
  16. Shop list screen APP Format shop data (Domain Logics) Shop

    List Recommend Banner Order history Header Generate Shop List Data Set Generate Chain List Data API - Specific shop list - Chain store - Recommend shops - Order history - Banner Problem of the shop list screen: Data flow
  17. Shop ist screen APP Format Shop data (Domain Logics) Shop

    List Header Generate Shop List Data Set Generate Chain List Data API Problem of the shop list screen: Data flow - Specific Shop List - Chain store
  18. Generate Shop List Data Set Generate Chain List Data Shop

    list screen APP Format Shop data (Domain Logics) Shop List Recommend Banner Order history Header API Over 300 Lines in 1 function ! Problem of the shop list screen: Data flow - Specific shop list - Chain store - Recommend shops - Order history - Banner
  19. Class Components - Unsafe lifecycle function - No React hooks

    - Not simple Legacy Problem of the shop list screen: Legacy React architecture
  20. Function Components - Uses React hooks - Uses custom hooks

    - Simple Modern Problem of the shop list screen: Legacy React architecture
  21. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  22. Approach to problems: Summary • Problem: Huge response and its

    delay • Implement paging • Recode the processes that depend on the responses • Problem: Complex data flow • Redefine each API responsibility • Move the data flow to a BFF layer • Problem: Legacy class component implementation • Use function components instead of class components • Split components • Separate UI and business logic by using hooks Data flow Legacy React architecture Data fetching
  23. Replace No paging Paging Shop List API Shop Search API

    Approach to problems: Data fetching
  24. all shop data sets Depend on Format Shop data (Domain

    Logics) Shop List Generate Shop List Data Set Generate Chain List Data Approach to problems: Data fetching
  25. New APIs Replace Format Shop data (Domain Logics) Shop Search

    Specific Shops Chain store Approach to problems: Data fetching
  26. Approach to problems: Data flow Shop list screen APP Shop

    List Recommend Banner Order history Header Generate Shop List Data Set Generate Chain List Data API - Specific shop list - Chain store - Recommend shops - Order history - Banner Format Shop data (Domain Logics)
  27. Shop list screen APP Recommend Banner Order history Header API

    Shop search Specific shops Chain store Approach to problems: Data flow - Specific shop list - Chain store - Recommend Shops - Order history - Banner Format Shop data (Domain Logics)
  28. BFF Shop search Chain store Recommend Order history Banner API

    iOS/Android Web Data formatting Approach to problems: Data flow Specific Shops
  29. Shop list screen APP Recommend Banner Order history Header API

    Shop search Recommend Banner Order history BFF Shop list Specific shops Chain store Approach to problems: Data flow Specific shops Chain store - Specific shop list - Chain store - Recommend shops - Order history - Banner Format Shop List Format Specific Shops Format order history Format recommend Format banner Format chain store
  30. Function components - Rendering logic - Snapshot Testing Replace Custom

    hooks - Data fetch logic - Unit Testing Class Components - Rendering logic - Data fetch logic - Unsafe Lifecycle Function - Difficult to split UI and business logic - No testing code Function components - Rendering logic - Snapshot Testing React hooks - Lifecycle logic - State logic - Unit Testing Approach to problems: Legacy React architecture
  31. Shop list screen APP Recommend shops Banner Order history Specific

    shop list Chain store useBannerQuery useShopListQuery useSpecific ShopsQuery useShopListData Shop list Approach to problems: Legacy React architecture useChainStoreQuery useRecommend Query useOrderHistoryQuery
  32. Approach to problems: Legacy React architecture useBannerQuery useShopListQuery usePersonalisedShop Query

    useShopListData useBannerQuery useShopListQuery useSpecific ShopsQuery useShopListData useChainStoreQuery useRecommend Query useOrderHistoryQuery
  33. APP useBannerQuery useShopListQuery usePersonalisedShop Query useShopListData Approach to problems: Legacy

    React architecture Recommend Banner Order history BFF Shop list Specific shops Chain store Format Shop List Format Specific shops Format order history Format recommend Format banner Format chain store
  34. Agenda • About Demae-can • Refactoring background • Problem of

    the shop list screen • Approach to problems • Refactoring Results
  35. Refactoring Results: Summary • Improve the huge response and its

    delay • Improve test coverage Architecture Performance • Use function components • Use a more declarative UI style Others • Remove unnecessary features • Motivate developers
  36. After Recommend Banner Order history API Shop search Specific shops

    Chain store Refactoring Results: Architecture Recommend Banner Order history BFF Shop list Specific shops Chain store Format Shop list Format Specific Shops Format order history Format recommend Format banner Format chain store
  37. Shop list screen APP Format data (Domain Logics) Header Generate

    Shop List Data Set Generate Chain List Data Before - Specific shop list - Chain store - Recommend - Order history - Banner Refactoring Results: Architecture
  38. Shop list screen APP Recommend Banner Order history Specific shop

    list Chain store useBannerQuery useShopListQuery usePersonalisedShop Query useShopListData Shop list After Refactoring Results: Architecture
  39. 0 500 1000 1500 2000 2500 3000 ShopList API (No

    Paging) ShopSearch API (Paging) 2.9 MB 327 KB Refactoring Results: Performance
  40. 0 100 200 300 400 500 600 700 800 900

    ShopList API (No Paging) ShopSearch API (Paging) 800 msec 320 msec Refactoring Results: Performance