Scaling Slack’s Mobile Codebases: Modularization

In the first post about the Duplo initiative, we discussed the reasons for launching a project to revamp Slack’s mobile codebases, and what we accomplished in Duplo’s initial Stabilization phase. This post will explore modularization, and then there will be a third post to describe how we modernized our codebase and the overall results of…

Tracy Stampfli
15 min readadvanced
--
View Original

Overview

The article discusses the modularization of Slack's mobile codebases as part of the Duplo initiative, focusing on the benefits of breaking apart app targets into smaller components. It highlights the integration of modularization with modernization efforts and the adoption of Bazel as a build system to enhance development efficiency.

What You'll Learn

1

How to modularize a mobile codebase to improve build times and developer autonomy

2

Why adopting Bazel as a build system can enhance development efficiency

3

How to implement code generation to reduce boilerplate code in mobile applications

Prerequisites & Requirements

  • Understanding of mobile app architecture and design patterns
  • Familiarity with Bazel and Gradle build systems(optional)

Key Questions Answered

What are the benefits of modularizing a mobile codebase?
Modularizing a mobile codebase improves build times, allows independent development, clarifies code ownership, and enhances the overall structure by reducing interdependencies. This leads to a more manageable codebase where developers can work more efficiently without stepping on each other's toes.
How does Bazel improve the development process for mobile applications?
Bazel improves the development process by simplifying module creation, reducing merge conflicts in project files, and enabling static linking of libraries, which enhances performance. It also supports a shared build cache, making it easier to manage dependencies and build times.
What types of modules are defined in Slack's iOS and Android codebases?
Slack defines three types of modules: Feature modules for presenting app features, Service modules for specific functions like API calls, and Library modules for reusable code. This structure helps maintain clear separation of responsibilities and reduces coupling between components.
What role does code generation play in Slack's mobile development?
Code generation helps improve developer experience by automating the creation of modules and reducing boilerplate code. It allows developers to quickly generate necessary project files and maintain consistency across the codebase, which enhances productivity.

Key Statistics & Figures

Improvement in compile time
Seconds saved per file moved to a module
On iOS, simply moving a file into a module without any other changes resulted in improved compile times.
Build time savings
20-45 seconds
Configuration caching in Gradle has saved this amount on successive builds after a configuration change.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Build System
Bazel
Used for managing the build process and dependencies in Slack's modularization effort.
Build Tool
Gradle
Continued to be used for building Android applications with optimizations for modularization.
Dependency Injection
Dagger
Used for managing dependencies in the Android codebase.
Programming Language
Kotlin
Utilized for Android development, particularly with Dagger and KAPT.

Key Actionable Insights

1
Consider breaking your mobile application into smaller modules to improve build times and developer efficiency.
This approach allows developers to work independently, reduces interdependencies, and clarifies code ownership, ultimately leading to a more manageable codebase.
2
Adopt Bazel as your build system to streamline the module creation process and minimize merge conflicts.
Bazel's capabilities in managing dependencies and build caching can significantly enhance the performance of your mobile development workflow.
3
Implement code generation techniques to automate repetitive tasks and reduce boilerplate code in your projects.
By using scripts and templates for code generation, you can improve consistency and speed up the development process, allowing developers to focus on more complex tasks.

Common Pitfalls

1
Failing to clearly define module ownership can lead to confusion and unmaintained code.
Without clear ownership, code can become 'unowned', making it difficult to track progress and responsibilities. Establishing clear ownership for each module helps prevent this issue.
2
Overcomplicating dependency injection can slow down compilation and increase boilerplate code.
Using a complex 'dependency injection graph of dependency injection graphs' approach can lead to slower builds and confusion. Simplifying the dependency injection strategy can enhance performance and maintainability.

Related Concepts

Mobile Application Architecture
Modular Design Patterns
Build System Optimization Techniques