Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Modular Architecture with Bazel

Ryo Aoyama
September 21, 2020

Micro Modular Architecture with Bazel

iOSDC Japan 2020 09/21 11:30 Track E
「Bazelを利用したMicro Modular Architecture」

Ryo Aoyama

September 21, 2020
Tweet

More Decks by Ryo Aoyama

Other Decks in Programming

Transcript

  1. Agenda • Drawbacks of Monolith • Micro Modular Architecture •

    What is Bazel? • The power of Bazel with micro modules
  2. FeatureA FeatureB FeatureC FeatureD FeatureZ … Networking DesignSystem Analytics Database

    Architecture etc… Entity Monolithic Application All features are concentrated in one or a few modules.
  3. Barriers to evolutionary potential: Monolithic Application The introduction of new

    technology affects the entire app and is pretty costly. And also, it does not have the ability to evolve progressively.
  4. Concepts One module has only one screen (aka view controller).

    All the layers needed for the screen are also in the same module. • Module by feature
  5. Concepts The screens do not depend on each other and

    work independently. • Independent between features
  6. Concepts Create one module for just one functionality. Larger functionalities

    consist of a composition of these smaller modules. • Fine-grained shared functionality modules
  7. Application Feature Feature Feature Feature Feature Common Common Common Common

    Modularization Group The modules in this group contain an App Delegate, and that's it. It might also contain DI to feature modules. Applications
  8. Application Feature Feature Feature Feature Feature Common Common Common Common

    Modularization Group Features Each vertical feature module is independent and can only depend on modules in the Domain and Libraries groups.
  9. Application Feature Feature Feature Feature Feature Common Common Common Common

    Modularization Group Domain (Library) Contains modules of functionality shared by several feature modules. It also allows modules to have service-specific information.
  10. Application Feature Feature Feature Feature Feature Common Common Common Common

    Modularization Group Libraries Contains modules of generalized functionality. It cannot have service-specific information.
  11. Modularization Group Applications Features Libraries Domain Grouping modules and make

    them unidirectional dependencies. Circular dependency Complexity
  12. Bazel • Fast + Reliable + Scalable + Extensible •

    Multiple language support • Starlark language for build scripts • Remote Caching • Open Source https://github.com/bazelbuild/bazel
  13. Example of Benefits My product completes clean build, unit test,

    and land to testers in around 1m 30s in the shortest. But it's still too early stage for a sample.
  14. Example of Benefits Pinterest https://medium.com/pinterest-engineering/developing-fast-reliable-ios-builds-at-pinterest-part-one-cb1810407b92 Local Build: CI Build: Beta

    Distribution: Build Success Rate: 4m 38s -> 3m 38s, 21% improved 10m 24s -> 7m 34s, 27% improved 14m 32s -> 7m 52s, 45% improved 80% -> 97%-100%
  15. Build Scripts WORKSPACE Defines external dependencies. BUILD Contains build scripts

    for 1~N modules. .bazelrc Configuration file for project-specific options. xxx.bzl Defines utility extension for build scripts which will be loaded from the BUILD.
  16. How to build load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "build_bazel_rules_apple", sha256

    = “….", url = “https://github.com/bazelbuild/rules_apple/releases/download/x.x.x/rules_apple.x.x.x.tar.gz”, ) load( "@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies", ) apple_rules_dependencies() load( "@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies", ) swift_rules_dependencies() load( "@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies", ) apple_support_dependencies() WORKSPACE
  17. Library How to build load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") swift_library( name = "Sample",

    srcs = glob(["Sources/**/*.swift"]), data = glob(["Resources/**/*"]), visibility = ["//visibility:public"], ) BUILD
  18. Application How to build load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") swift_library( name

    = "AppLib", srcs = glob(["App/**/*.swift"]), ) ios_application( name = "App", app_icons = glob(["Assets.xcassets/AppIcon.appiconset/**"]), bundle_id = "com.example.app", families = [ "iphone", "ipad", ], infoplists = ["Info.plist"], launch_storyboard = "Launch.storyboard", minimum_os_version = "14.0", deps = [":AppLib"], ) BUILD
  19. How to build $ bazel build //… Build all targets

    $ bazel build //package-name:target-name Build specified target
  20. Carthage CocoaPods • pinterest/PodToBUILD • bazel-ios/cocoapods-bazel • with build scripts:

    swift_library, objc_library • with build scripts: apple_dynamic_framework_import Our Choice Third-party Library
  21. index-import by Lyft https://github.com/lyft/index-import Bazel + Xcode Replaces the paths

    in the index file created by Bazel so that it can be used for Xcode.
  22. Downside • High adoption cost • High learning cost •

    iOS is not officially supported • Some Xcode features have been disabled
  23. Aggressive Caching Once a module is built, it won't be

    rebuilt until the code in that module is changed.
  24. Remote Caching Once it's built somewhere, all developers don't have

    to rebuild it. Build once, reuse everywhere:
  25. Static Linking Too many dynamic frameworks can have a negative

    impact on the launch speed of your app.
  26. Dependency Diagrams Bazel can track all dependency graphs and parse

    them with the bazel query command. It can be output as a graphical diagram with Graphviz.
  27. • Micro Modular Architecture maximizes the synergy with Bazel, and

    vice versa. Conclusion • Build speed has room for improvement in software architecture as well as hardware performance. • Bazel will dramatically improve our developer experience.
  28. References • Bazel Document • Faster Together: Uber Engineering’s iOS

    Monorepo • How Tokopedia Achieved 1000% Faster iOS Build Time • Improving Build Performance of LINE for iOS with Bazel • Developing fast & reliable iOS builds at Pinterest (Part one) • kastiglione/bazel-xcode-demo-swift-driver https://eng.uber.com/ios-monorepo https://engineering.linecorp.com/en/blog/improving-build-performance-line-ios-bazel https://medium.com/tokopedia-engineering/how-tokopedia-achieved-1000-faster-ios-build-time-7664b2d8ae5 https://medium.com/pinterest-engineering/developing-fast-reliable-ios-builds-at-pinterest-part-one-cb1810407b92 https://bazel.build https://github.com/kastiglione/bazel-xcode-demo-swift-driver