@naopr
● Backend Engineer at Mercari, Inc.
● Tech Lead of CSTool Team
● Love
Slide 3
Slide 3 text
Relationship between Mercari & Sendai
Sendai
Reply to inquiries
Monitor contents
Fukuoka
Call-center
Tokyo
Head Office
Develop apps
Slide 4
Slide 4 text
Relationship between Mercari & PHP
● Mercari app’s API is written in PHP
● Migrating to microservices
○ From PHP to Go
○ Break down existing API into multiple services
○ MTC2018 - Mercari API: from Monolithic to Microservices
Slide 5
Slide 5 text
Technique to delete
unused codes
Slide 6
Slide 6 text
Agenda
● Why do we need to delete unused codes?
● Mercari’s case
○ How to delete unused codes
○ Result
● Conclusion
Slide 7
Slide 7 text
Why do we need to delete unused codes?
● Reduce development costs
○ Reading cost
○ Updating cost
● Speed up the system
○ Response time
○ CI
Slide 8
Slide 8 text
How to delete unused codes
Detect unused APIs
Build project team
Delete codes
1
2
3
Slide 9
Slide 9 text
Detect unused APIs
1. List APIs that haven’t been recently accessed
a. For a month in our case
b. Use Google BigQuery & a script written in Go
2. Check if we may delete the API
a. Investigate codes
b. Use `git blame` and ask implementer
c. Find tickets related to it
Slide 10
Slide 10 text
Make API list by spreadsheet
Slide 11
Slide 11 text
Build project team
● Collect fellows [Important]
○ backend engineer
○ QA engineer
● Decide the release procedure
○ How to do QA
○ JIRA ticket
● Hold a kick-off with
○ Better to hold it every month
Slide 12
Slide 12 text
Delete codes
● Check recent access log
● Check methods recursively
○ Type and type `git grep`!
○ With symbol search function by PhpStorm
○ Controller, Service, Exception, Entity, DB table, DB schema, test, etc...
Slide 13
Slide 13 text
Result
Slide 14
Slide 14 text
Result summary
● Deleted 349 / 370 (≒94%) unused APIs
○ In 3 months
○ 7 backend engineers + 1 frontend engineers
○ About 80k〜100k lines
● Reverted 9 PRs
○ Other repositories were affected when tables were dropped
○ Forgot to check the access log
Slide 15
Slide 15 text
Conclusion
Slide 16
Slide 16 text
Deleting code is difficult
● Need to read the code steadily or ask a senior engineer
● Do it with fellows, NOT alone
● Don’t forget to check the access log
● Check the impact on other repositories when drop tables
● Let’s hold a drinking party every month