Share
Embed
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
Transcript
51 slides
-
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 -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
About Demae-can: Our business One of the largest food delivery
company in Japan -
About Demae-can: Our business One of the largest food delivery
company in Japan Merchants -
About Demae-can: Our business One of the largest food delivery
company in Japan Active Users -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
2021.4~ 2020.3 Capital business partnership 2020.5 First app developer joined
Demae-can Refactoring background: History We joined Demae-can app team -
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 -
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 -
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 -
Free shipping campaign UI, UX PJ Business PJ Refactoring background:
Software product quality Maintainability Usability -
Implement universal links and AppLinks UI, UX PJ Business PJ
Refactoring background: Software product quality Maintainability Usability -
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? -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
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 -
Shop List Screen APP Shop list Recommend Order history Banner
API Problem of the shop list screen: Data fetching -
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 -
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 -
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 -
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 -
Class Components - Unsafe lifecycle function - No React hooks
- Not simple Legacy Problem of the shop list screen: Legacy React architecture -
Function Components - Uses React hooks - Uses custom hooks
- Simple Modern Problem of the shop list screen: Legacy React architecture -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
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 -
Replace No paging Paging Shop List API Shop Search API
Approach to problems: Data fetching -
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 -
New APIs Replace Format Shop data (Domain Logics) Shop Search
Specific Shops Chain store Approach to problems: Data fetching -
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) -
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) -
BFF Shop search Chain store Recommend Order history Banner API
iOS/Android Web Data formatting Approach to problems: Data flow Specific Shops -
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 -
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 -
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 -
Approach to problems: Legacy React architecture useBannerQuery useShopListQuery usePersonalisedShop Query
useShopListData useBannerQuery useShopListQuery useSpecific ShopsQuery useShopListData useChainStoreQuery useRecommend Query useOrderHistoryQuery -
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 -
Agenda • About Demae-can • Refactoring background • Problem of
the shop list screen • Approach to problems • Refactoring Results -
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 -
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 -
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 -
Shop list screen APP Recommend Banner Order history Specific shop
list Chain store useBannerQuery useShopListQuery usePersonalisedShop Query useShopListData Shop list After Refactoring Results: Architecture -
0 500 1000 1500 2000 2500 3000 ShopList API (No
Paging) ShopSearch API (Paging) 2.9 MB 327 KB Refactoring Results: Performance -
0 100 200 300 400 500 600 700 800 900
ShopList API (No Paging) ShopSearch API (Paging) 800 msec 320 msec Refactoring Results: Performance