Building Mobile Apps at Scale Building Mobile Apps at Scale 39 Engineering Challenges Copyright © 2021 by Gergely Orosz All rights reserved. No part of this book may be reproduced or used inany manner without written permission of the copyright owner except for the use of quotations in a book review.For more information, please address: [email protected]. ISBN: 978-1-63795-844-5 (ebook) FIRST EDITION, v1.0 www.MobileAtScale.com 2 Building Mobile Apps at Scale Table of Contents Introduction 5 Acknowledgements 6 About the Author 7 Sponsors 8 When Things are Simple 10 PART 1: Challenges Due to the Nature of Mobile Applications 11 1. State Management 12 2. Mistakes Are Hard to Revert 15 3. The Long Tail of Old App Versions 17 4. Deeplinks 18 5. Push and Background Notifications 19 6. App Crashes 21 7. Offline Support 25 8. Accessibility 28 9. CI/CD & The Build Train 30 10. Third-Party Libraries and SDKs 36 11. Device and OS Fragmentation 38 12. In-App Purchases 40 PART 2: Challenges Due to App Complexity 47 13. Navigation Architecture Within Large Apps 48 14. Application State & Event-Driven Changes 51 15. Localization 53 16. Modular Architecture & Dependency Injection 57 17. Automated Testing 58 3 Building Mobile Apps at Scale 18. Manual Testing 62 PART 3: Challenges Due to Large Engineering Teams 64 19. Planning and Decision Making 65 20. Architecting Ways to Avoid Stepping on Each Other’sToes 67 21. Shared Architecture Across Several Apps 69 22. Tooling Maturity for Large Engineering Teams 71 23. Scaling Build & Merge Times 72 24. Mobile Platform Libraries and Teams 74 PART 4: Languages and Cross-Platform Approaches 80 25. Adopting New Languages and Frameworks 81 26. Kotlin Multiplatform and KMM 83 27. Cross-Platform Feature Development 87 28. Cross-Platform App Development versus Native 90 29. Web, PWA & Backend-Driven Mobile Apps 95 PART 5: Challenges Due to Stepping Up Your Game 98 30. Experimentation 99 31. Feature Flag Hell 102 32. Performance 105 33. Analytics, Monitoring and Alerting 111 34. Mobile On-Call 117 35. Advanced Code Quality Checks 119 36. Compliance, Privacy and Security 122 37. Client-Side Data Migrations 125 38. Forced Upgrading 126 39. App Size 129 Closing Thoughts 132 4 Building Mobile Apps at Scale Introduction I have noticed that while there is a lot of appreciationfor backend and distributed systems challenges, there is often less empathy for why mobile developmentis hard when done at scale.Building a backend system that serves millions of customers means buildinghighly available and scalable systemsandoperating these reliably. But what about the mobile clientsfor the same systems? Most engineers who have not built mobile apps assumethe mobile app is a simple facade that requires less engineering effort to build and operate. Having builtboth types of systems, I can say this is not thecase. There is plenty of depth in building large, native,mobile applications, but often little curiosity frompeople not in this space. Product managers, business stakeholders,and even non-native mobile engineers rarely understand why it "takes so long" to ship somethingon mobile. This book collects challenges engineers face whenbuilding iOS and Android apps at scale.By scale,I mean having numbers of users in the millions and beingbuilt by large engineering teams. These teams launch features continuously and still ensure theapp works reliably, and in a performant way. This book is a summary of the current industry practicesused by large, native mobile teams and points to some of the common approaches to tackle them. Muchof the experience conveyed in this book comes from my time working at Uber on a complex and widely-usedapp. More than 30 other engineers working in similarly complex environments have contributed theirinsights; engineers building apps at the likes ofTwitter, Amazon, Flipkart, Square, Capital One and many othercompanies. I hope this book helps non-mobile engineers buildempathy for the type of challenges and tradeoffs mobile engineers face and be a conversation starter betweenbackend, web, and mobile teams. 5 Building Mobile Apps at Scale Acknowledgements The book has been written with the significant inputand reviews of more than 30 mobile engineers and managers, many of them deep experts in their respectivefields. Thank you very much to all of them. If youare on Twitter, I suggest you follow them: ● Abhijith Krishnappa(Halodoc) ● Jorge Coca(VG Ventures) ● Andrea Antonioni(Just Eat) ● Julian Harty(previously Google, eBay, ● Andreea Sicaru(Uber) Badoo, Salesforce, Klarna, ServiceNow, and ● Andy Boedo(RevenueCat, Elevate Labs) others) ● Ankush Gupta(Quizlet) ● Leland Takamine(perf.dev, Uber) ● Artem Chubaryan(Square) ● Matija Grcic(EMG Consulting) ● Barnabas Gema(Shapr3D) ● Michael Bailey(GDE, American Express) ● Barisere Jonathan(Sprinthubmobile) ● Michael Sena(Tesla, Amazon) ● Corentin Kerisit(Zenly) ● Nacho Lopez(Twitter, Facebook, Yahoo) ● Dan Kesack(DraftKings) ● Patrick Zearfoss(Capital One) ● Edu Caselles(Author:The Mobile Interview, ● Praveen Sanap(Carousell) Funding Circle) ● Paul Razgaitis(Cameo, Braintree, Venmo) ● Emmanuel Goossaert(Booking.com) ● Robin van Dijke(Uber, Apple) ● Franz Busch(Sixt) ● Rui Peres(Sphere, Babylon Health) ● Guillermo Orellana(Monzo, Skyscanner, ● Sabyasachi Ruj(Flipkart, CloudMagic, Badoo) Webyog) ● Injy Zarif(Convoy, Microsoft) ● Sathvik Parekodi ● Jake Lee(Photobox) ● Tuğkan Kibar ● Jared Sheehan(Capital One) ● Tuomas Artman(Linear, Uber) ● Javi Pulido(Plain Concepts) ● Wouter van den Broek Thank you to Emmanuel Goossaert for writing most ofChapter 10: Third-Party Libraries and SDKs. Special thanks to the editor of the book,DominicGoveratBest English Copyfor helping create a bookthat is pleasant to read. 6 Building Mobile Apps at Scale About the Author Gergely has been building native mobile apps since2010, starting on Windows Phone, later on iOS, and Android. Starting from one-personapps, he worked with small teams at Skyscanner, to hundreds of engineersworking on the same codebase at Uber. At Uber, he worked on theRiderandDriver app rewrites,both projects involving hundreds of mobile engineers. The apps he worked onhad more than 100 million monthly users in more than 60 countries, withseveral features built for a single country or region. You can readbooks he has written, browseThe PragmaticEngineer Bloghe writes andconnect with himon social media channels. 7 Building Mobile Apps at Scale Sponsors Publishing of this book has been sponsored by vendorsproviding world-class mobile engineering solutions. Using vendor solutions over building your own is oftenthe pragmatic approach: this allows you to focuson providing business value over maintaining infrastructure. Bitriseis CI/CD built for mobile - by mobile engineers.From pull request, to app store submission and beyond, Bitrise automates, monitors and improves yourapp development workflows. Teams who use Bitrise build better quality apps, deliver them faster, withdevelopers who are happy. Bitrise supports native Android or iOS, React Native,Flutter and other mobile builds. More than 100,000 developers and thousands of organizations trust Bitriseto increase productivity.Try Bitrise for free, today,and build better apps, faster. Bugsnagis an error monitoring and application stabilitymanagement solution. Not all bugs are worth fixing, and stability is the key to making data-driven decisionson whether to build software or to fix bugs. Bugsnag is a daily stability dashboard for mobileengineers, product managers, release managers, and observability teams to manage quality applications.We help drive code ownership, balance faster release cycles, reduce technical debt, and improve user experience. Processing over a billion crash reports a day, Bugsnagis used by over 6,000 of the world’s best small and large engineering teams such as Airbnb, Slack, Square,Lyft, Shopify and Tinder.Get started for free today. SonarSourcebuilds world-class code quality and securitytools used by more than 200,000 engineering teams. Open-source and commercial code products thathelp you find and fix bugs, vulnerabilities and code smells, so you deliver better mobile apps. SonarCloud is the leading code static analysis andcode security tool, integrating with GitHub, GitLaband other providers. It integrates directly into yourcode review workflow, and helps assess your code health.Free to use for open source projects -get started now. SonarQube is the on-premise code quality and securitytool supporting Swift, Kotlin, Objective C, Java,and 23 other languages. Detect code smells, common bugs,and security hotspots.Get started for free. 8 Building Mobile Apps at Scale RevenueCatmakes it easy to build and manage iOS andAndroid in-app purchases at scale. With a few lines of code RevenueCat provides IAP infrastructure, customeranalytics, data integrations, and gives you time back from dealing with edge cases and updates acrossthe platforms. Created by developers, for developers, thousands ofthe world’s best apps use RevenueCat to power their in-app purchases and subscriptions.Get started forfree here. Touchlabis trusted by mobile innovators to scaleKotlin Multiplatform Mobile (KMM). Touchlab accelerates KMM adoption through product & SDK development, earlyadopter support, architectural & production-readiness reviews and open-source projects. Touchlab advises enterprises like Square and NBC onscaling KMM and partners with JetBrains to increase KMM adoption. Looking to get started with KMM? Checkout theirKotlin Multiplatform starter kit. Perf.devis an industry-leading mobile performanceplatform and enables a proactive workflow for managing mobile performance. The platform provides automated testing and root causeanalysis to address performance issues before releasing to end-users.Upgrade your mobile performancestrategy. Craft Docsis the modern writing app, native for MacOS,iPhone and iPad, built with Catalyst. Perfect from note-taking to collaborating within a team. Most peoplewho try Craft say the same: that this is the appthey've been looking for all this time.Try Craft for free. Linearis the issue tracking tool you'll enjoy using- built for software teams who want to build highquality products. Linear helps to streamline your team’s softwareprojects, sprints and tasks. Integrated with Github, Gitlab, Figma and Slack. On MacOS, Web and Mobile.Start using it for free. 9 Building Mobile Apps at Scale When Things are Simple Let's address the elephant in the room: the frequentassumption that client-side development is simple.The assumption that the biggest complexity lies in makingsure things look good on various mobile devices. When the problem you are solving is simple, and thescope is small, it is easier to come up with simple solutions.When you are building an app with limitedfunctionality with a small team and very few users,your mobile app should not be complicated. Your backendwill likely be easy to understand. Your website willbe a no-brainer. You can use existing libraries, templates,and all sorts of shortcuts to put working solutionsin place. Once you grow in size — customers, engineers, codebaseand features — everything becomes more complex, more bloated, and harder to understand andmodify, including the mobile codebase. This is thepart we focus on in this book; when things become complex.When your app gets big, there are no silver bullets that will magically solve all of your pain points,only tough tradeoffs to make. This book begins at the point at which your app stopsbeing simple. 10