how to get away with murder refactoring
play

How to get away with murder refactoring @qcmaude This is me (and - PowerPoint PPT Presentation

How to get away with murder refactoring @qcmaude This is me (and Chewbacca). I work at & live in San Francisco. How to Get Away with Refactoring @qcmaude 2 /57 Drummondville, QC How to Get Away with Refactoring


  1. How to get away with murder refactoring @qcmaude

  2. This is me (and Chewbacca). I work at & live in San Francisco. How to Get Away with Refactoring @qcmaude � 2 /57

  3. Drummondville, QC How to Get Away with Refactoring @qcmaude � 3 /57

  4. McGill Rent the Runway How to Get Away with Refactoring @qcmaude � 4 /57

  5. WARNING: This presentation contains pictures of cake and other baked goods courtesy of The Great British Bake Off. How to Get Away with Refactoring @qcmaude � 5 /57

  6. Agenda 1. Refactoring • what it is • why do it 2. In Practice 3. Lessons Learned How to Get Away with Refactoring @qcmaude � 6 /57

  7. Refactoring a definition n. the process of restructuring existing code (e.g. the factoring ) without changing its external behaviour How to Get Away with Refactoring @qcmaude � 7 /57

  8. Monique’s Millefeuille Boil milk in medium saucepan. 1. Place 1/10 inch-thick puff pastry in the oven at 350 ˚ F. 2. Whisk the eggs, sugar, vanilla and flour in a bowl. (white all-purpose flour is best) about 15 minutes on 3. Add boiled milk to the bowl. 4. Return mixture to saucepan for a medium heat. few minutes until it has a cream- like texture. 5. When the puff pastry is cooked, cut t e s n u into three even pieces. m i 1 0 a k e d t o u l s h k e - l i a m c r e h e s t r e i s i è â t i s p m e c r è * 6. Layer the crème pâtissière between a d e m u s t w e j r e t u m i x layers of pastry and let cool. How to Get Away with Refactoring @qcmaude � 8 /57

  9. How to Get Away with Refactoring @qcmaude � 9 /57

  10. but, in the world of business , it’s a little more complicated than that ... How to Get Away with Refactoring @qcmaude � 10 /57

  11. Reasons to Refactor 1. for fun 2. out of boredom 3. “ happen to be passing by ” 4. to make the code more legible or extendable How to Get Away with Refactoring @qcmaude � 11 /57

  12. “ If it ain’t broken, don’t fix it. ” How to Get Away with Refactoring @qcmaude � 12 /57

  13. Reasons to Refactor 1. shift in product requirements 2. adopting a new technology 3. improving performance How to Get Away with Refactoring @qcmaude � 13 /57

  14. How to Get Away with Refactoring @qcmaude � 14 /57

  15. Refactoring can … • cause serious regressions • unearth dormant bugs • easily grow in scope • introduce unnecessary complexity How to Get Away with Refactoring @qcmaude � 15 /57

  16. So, let’s not kid ourselves ... How to Get Away with Refactoring @qcmaude � 16 /57

  17. Refactoring the real definition n. the process by which we take a pile of poo and turn it into a shinier pile of poo How to Get Away with Refactoring @qcmaude � 17 /57

  18. In Practice How to Get Away with Refactoring @qcmaude � 18 /57

  19. May 2017 How to Get Away with Refactoring @qcmaude � 19 /57

  20. Narrow it down: What’s the actual problem? How to Get Away with Refactoring @qcmaude � 20 /57

  21. unread public and private channels DMs and group DMs How to Get Away with Refactoring @qcmaude � 21 /57

  22. By the numbers # of public & private # of channel # of channels on top channels on top five memberships on top five teams* teams* five users* 80 301 5 841 454 8 338 590 69 296 1 926 918 102 569 60 029 1 819 719 100 647 55 043 1 527 894 66 311 49 697 1 524 953 61 101 * only looks at totals on a single team (non-aggregate view of Enterprise customers) How to Get Away with Refactoring @qcmaude � 22 /57

  23. We have two tables that store nearly identical information: 1. teams_channels stores a row for each public channel 2. groups stores a row for each private channel or group DM How to Get Away with Refactoring @qcmaude � 23 /57

  24. Correspondingly, we have yet another two tables that store nearly identical information: 1. teams_channels_members stores a row for each user’s membership in a public channel 2. groups_members stores a row for each user’s membership in a private channel or group DM How to Get Away with Refactoring @qcmaude � 24 /57

  25. Slack in mid-2017 public channels private channels DMs channel teams_channels groups teams_ims membership teams_channels_members groups_members C123456 G123456 D123456 How to Get Away with Refactoring @qcmaude � 25 /57

  26. 
 
 We end up with a ton of similar queries to two tables and lots of 
 UNION 
 UNION ALL 
 LEFT (OUTER) JOIN 
 which isn’t great for performance How to Get Away with Refactoring @qcmaude � 26 /57

  27. SQL Performance 102 • UNION removes duplicate records. • UNION ALL returns all columns (no extra distinctness check). • LEFT OUTER JOIN is faster than LEFT INNER JOIN . • Use EXPLAIN all day every day. How to Get Away with Refactoring @qcmaude � 27 /57

  28. do some stuff do some other stuff How to Get Away with Refactoring @qcmaude � 28 /57

  29. Get some context: Why was it designed this way originally ? How to Get Away with Refactoring @qcmaude � 29 /57

  30. 1. Security: keeping private channel information in a separate table isolates it 2. Product history: channels and private channels seemed like vastly different concepts 3. Inability to travel into the future How to Get Away with Refactoring @qcmaude � 30 /57

  31. Put on you thinking cap: Brainstorm a Solution & Identify the Challenges How to Get Away with Refactoring @qcmaude � 31 /57

  32. Remember this? public channels private channels DMs channel teams_channels groups teams_ims membership teams_channels_members groups_members C123456 G123456 D123456 How to Get Away with Refactoring @qcmaude � 32 /57

  33. Consolidate into a single channels_members table How to Get Away with Refactoring @qcmaude � 33 /57

  34. Let’s do this ! public channels private channels DMs channel teams_channels groups teams_ims membership channels_members C123456 G123456 D123456 How to Get Away with Refactoring @qcmaude � 34 /57

  35. It might not be so simple ... • SQL queries are scattered throughout the code • About 400 callsites • ☝ embedded in old, crufty code from 3 years ago • Little to no unit test coverage How to Get Away with Refactoring @qcmaude � 35 /57

  36. Sell, sell, sell: Convince your team! How to Get Away with Refactoring @qcmaude � 36 /57

  37. 1. Our biggest customers won’t be able to handle the additional latency in a few months 2. Opportunity to easily modify a key table 3. Develop a pattern for future data consolidations How to Get Away with Refactoring @qcmaude � 37 /57

  38. Map it out: Write a Detailed Plan of Action How to Get Away with Refactoring @qcmaude � 38 /57

  39. How to Get Away with Refactoring @qcmaude � 39 /57

  40. Be careful: don’t bite off more than you can chew! How to Get Away with Refactoring @qcmaude � 40

  41. Expect the unexpected! How to Get Away with Refactoring @qcmaude � 41 /57

  42. A few other tips 1. Get feedback from folks on other teams 2. Think outside your codebase: could your changes affect other services, other folks’ pipelines, third-party developers, etc. 3. Be generous in your estimates How to Get Away with Refactoring @qcmaude � 42 /57

  43. Go, go, go: Execute! How to Get Away with Refactoring @qcmaude � 43 /57

  44. Feature flags are your friend . How to Get Away with Refactoring @qcmaude � 44 /57

  45. Bugs are inevitable. How to Get Away with Refactoring @qcmaude � 45 /57

  46. In case you’d forgotten public channels private channels DMs channel teams_channels groups teams_ims membership channels_members C123456 G123456 D123456 How to Get Away with Refactoring @qcmaude � 46 /57

  47. One step further public channels private channels DMs channel channels teams_ims membership channels_members C123456 G123456 D123456 How to Get Away with Refactoring @qcmaude � 47 /57

  48. 1. Dark mode: Read from both tables, compare the results, return the value from the old table . 2. Light mode: Read from both tables, compare the results, return the value from the new table . How to Get Away with Refactoring @qcmaude � 48 /57

  49. 1. Dark mode in dev environments. 2. Dark mode in production for a few weeks. 3. Light mode in dev for a two weeks. 4. Light mode to our team for one week. 5. Light mode to increasing % of teams in production over a 2 week period. How to Get Away with Refactoring @qcmaude � 49 /57

  50. Document, document, document. How to Get Away with Refactoring @qcmaude � 50 /57

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend