As the lead of a mobile app growing from one team to eight, how do you decide when to modularize, how fine-grained to go, and who owns each module?
answer
- small team, early product: not yet
- measured pain is the trigger
- cut where change and team coincide
- too fine is overhead, too coarse a monolith
- one owning team per module
basics
~20 sModularize when build time, merge friction or unclear ownership cost more than module overhead, rarely the case for one small team on an early product. Cut where what changes together meets who changes it; give each module one owning team.
solid answer
~50 sA single small team on an early product usually should not modularize yet: feature boundaries are still moving, and every module adds configuration and indirection that buys little build-time or ownership gain at that size. The trigger is pain you can measure: incremental builds that cost minutes, merge conflicts across teams, nobody sure who reviews a change. Then cut along two lines that should coincide, **what changes together** (high cohesion) and **who changes it** (one owning team per module). Too fine and the per-module overhead eats the gain; too coarse and the monolith reappears inside one module. Product teams own their feature modules; a platform team owns core modules and the app module with a stricter review bar, because their changes reach furthest. Write the dependency rules down, enforce them in the build, and revisit the cuts when teams reorganize.
go deeper
Recall that modules cost something to set up and maintain, so a small app may be better as one module with tidy folders.
Explain cohesion and coupling as the test for a boundary, and the symptoms of modules that are too coarse or too fine.
Name the measurable triggers for a split and plan a migration that keeps shipping, with the dependency check in place from the start.
Own the trade-off: align module boundaries with team ownership, give core modules a stricter bar, treat API modules as inter-team contracts, and decide when the cost of restructuring is worth paying.
## Modularization has a price Splitting an app into modules is not free, and the bill arrives before the benefits: - **Configuration per module**: each one has build settings to keep consistent with the rest. - **Indirection**: contracts between features, bindings in the composition root, more files to read before a change makes sense. - **Premature boundaries**: on an early product the features themselves are still being discovered, and a boundary drawn too soon has to be moved later, which is more expensive than moving a folder. The benefits, shorter incremental builds, enforced encapsulation and clear ownership, grow with the size of the code and the number of teams. For a small codebase that is not expected to grow much, the scalability and build-time gains may never arrive. ## Signals that it is time Treat it like any other investment: start when the cost of not doing it is measurable. 1. **Incremental builds** after a small change take minutes, and engineers batch changes to avoid them. 2. **Merge conflicts** between teams in the same files become routine. 3. **Ownership is unclear**: nobody knows who must review a change to a given screen or helper. 4. **Teams block each other**: one team cannot refactor because another depends on its internals. When none of these is true, tidy packages inside one module are a fine place to be, and the cheapest preparation for a later split. ## Choosing the cut Two properties decide where a boundary goes. **Cohesion**: code inside a module should belong to one capability and change together. **Coupling**: modules should know as little as possible about each other's internals. A useful test: if two modules always change together, they are one module; if two parts of a module never touch each other, they are probably two. The second line is organizational. A module edited by three teams has no real owner, and a team whose work spans five modules spends its days coordinating. Draw boundaries so that, most of the time, **one team's change stays inside modules that team owns**. When the org chart and the cohesion cut disagree, one of them is wrong, and it is worth finding out which. ## Granularity | Granularity | Symptom | What to do | |---|---|---| | **Too coarse** | A module holds several teams' code; every edit rebuilds all of it; reviews pull in strangers | Split along team and capability lines | | **About right** | Most changes touch one team's modules; hubs are small and stable | Keep enforcing the rules | | **Too fine** | Dozens of tiny modules that always change together; build configuration dominates; simple changes span many modules | Merge modules that move as one | ## The ownership model - **Every module has exactly one owning team**, recorded in a path-to-team ownership map that the review process enforces. - **Feature modules** belong to the product team that builds the feature. - **Core modules and the app module** belong to a platform team, with a stricter review bar, because a change there reaches every downstream module and every team. - **API modules are contracts between teams**: changing one needs the consuming teams' agreement, like any interface others rely on. - **The dependency rules** (acyclic, API-only edges between features, nothing above core) are owned by the platform team and enforced by a build check, with exceptions written down. ## Migrating an existing app 1. Add the dependency check first, so new code cannot create forbidden edges while old code is still moving. 2. Extract the **shared foundations** that features will need to depend on: UI components, networking, the data modules for the main domains. 3. Carve out **one feature at a time**, starting with leaves few others touch, while the original module shrinks. 4. Assign each new module its owning team on the day it is created. In the super-app, eight teams across ride-hailing, food delivery and the wallet, the end state is a few modules per team, a small platform-owned core, and an app module that only wires. Getting there is a quarter-scale project, not a weekend refactor, and that cost is exactly what the small team at the start was right to avoid.
- Two teams both need to change the same module in nearly every sprint. What does that tell you?The boundary does not match ownership. Either the module holds two concerns and should split along the line each team edits, or both teams are really working on one capability and ownership should move. A module with two owning teams effectively has none: reviews stall and its debt goes unpaid.
- How do you migrate a single-module app without stopping feature work?Incrementally. Add the dependency check first so the new graph cannot regress, extract the shared foundations features will depend on, then carve out one feature at a time, starting with leaves few others touch, while the original module shrinks. Feature work continues throughout, landing in whichever module currently owns that code.
- Every mobile app should be modularized from the first commit.
- The more modules an app has, the better its architecture.
- Modularizing makes builds faster whatever the size of the codebase.
- Splitting into modules costs nothing once the build is set up.
- Module boundaries never need to change once teams start using them.