YouTube2Text

Vertical vs. Horizontal Slicing - The ONLY Right Way to Split Down Your App — Transcript

by Philipp Lackner · 2,710 words · 415 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hi guys, and welcome back to a new
  2. 0:01video. Today we're going to take a look
  3. 0:03at vertical versus horizontal slicing
  4. 0:05for your mobile app. What should you
  5. 0:07actually stick to? If these terms are
  6. 0:09new to you, then don't no worries. I
  7. 0:11will actually go over exactly that in
  8. 0:13this video. And after watching this
  9. 0:14video, you will know exactly how you
  10. 0:17should actually take a big project and
  11. 0:19split this down and which parts of the
  12. 0:21app to approach in which order. But
  13. 0:23first of all, to just get the
  14. 0:24terminology right, vertical and
  15. 0:26horizontal slicing, maybe you've heard
  16. 0:27that before, but in the end, it's all
  17. 0:29about when you have a big project and
  18. 0:32you need to split this down into smaller
  19. 0:33parts in some way. There are of course
  20. 0:35multiple approaches that can work,
  21. 0:37multiple approaches to actually slice
  22. 0:39the app. And one of them is
  23. 0:41horizontally, and one of them is
  24. 0:43vertically. Vertical slicing in the end
  25. 0:45means if we have our app here, so this
  26. 0:47whole square would be our app. Vertical
  27. 0:49slicing would mean we split the app down
  28. 0:52by feature. So we would first of all
  29. 0:54build feature the the off feature for
  30. 0:56example. We would then move on to the
  31. 0:58note taking feature. then move on to the
  32. 1:01account feature. So we in the end take a
  33. 1:04look at the whole project and then say,
  34. 1:06"Okay, we first of all work on this
  35. 1:08feature, then on this feature, then on
  36. 1:09this feature." This is one way of
  37. 1:11slicing. Another way of slicing is
  38. 1:13horizontal slicing, where we in the end
  39. 1:15work on the app layer by layer. So here
  40. 1:18for example, we say, "Hey, we first of
  41. 1:20all build the entire UI for the entire
  42. 1:23app, for all features,
  43. 1:25then we work on the entire domain layer
  44. 1:27for all features of the app, and then on
  45. 1:28all the data layer on the data
  46. 1:30infrastructure for the entire app.
  47. 1:31That's also another alternative approach
  48. 1:33of actually slicing down such an app. So
  49. 1:35what is actually the right way now?
  50. 1:37Whatever you are doing, the very first
  51. 1:40thing for you to build is always the
  52. 1:42shared infrastructure. So the shared
  53. 1:44infrastructure usually also consists of
  54. 1:47multiple layers. That's at least the
  55. 1:48architecture that I stick stick to that
  56. 1:50I will also I'm sure you a practical
  57. 1:52example for a moment. But in the end,
  58. 1:54you have some kind of shared
  59. 1:55infrastructure, something common,
  60. 1:57something that all features need. For
  61. 1:59example, this could be some kind of
  62. 2:02error handling utility, or some kind of
  63. 2:04utility that you just need across the
  64. 2:06project. This
  65. 2:07could be some design system components,
  66. 2:09or very fundamental UI components like
  67. 2:12certain customized buttons or so that
  68. 2:15that multiple features need, some
  69. 2:17customized text fields or components.
  70. 2:20This could be UI related utility. For
  71. 2:22the for the data layer here of the
  72. 2:24shared infrastructure, this could be
  73. 2:25networking utility, so some kind of
  74. 2:28shared infrastructure,
  75. 2:30some shared networking utility that just
  76. 2:32all the different parts of the project
  77. 2:33may access. This could also be a
  78. 2:35database instance that the entire app
  79. 2:36needs to access and read data from. But
  80. 2:39since this is something that possibly
  81. 2:40all or at least multiple features need
  82. 2:42to access, that is what we need to work
  83. 2:44on first. Because without the shared
  84. 2:46infrastructure, we wouldn't be able to
  85. 2:48finish a single feature in the first
  86. 2:49place if that single feature needs the
  87. 2:51shared infrastructure. And specifically
  88. 2:53to this layering here, the UI, domain,
  89. 2:55data, you always want to start with the
  90. 2:57domain layer since that is the innermost
  91. 2:59layer according to this architecture.
  92. 3:02This is the layer that both UI and data
  93. 3:04will access, that both UI and data will
  94. 3:08have dependencies towards, not the other
  95. 3:09way around. Domain should be very very
  96. 3:12isolated in the middle of your onion
  97. 3:14kind of. That's how the clean
  98. 3:15architecture diagrams typically show
  99. 3:16this. And here it's actually the same
  100. 3:18concept within this little boxy for the
  101. 3:21shared infrastructure. So on an app
  102. 3:23level, we want to work on the shared
  103. 3:24infrastructure as a whole as a first
  104. 3:26thing because multiple parts of this app
  105. 3:28need to access that.
  106. 3:30But
  107. 3:31when taking a look at the shared
  108. 3:32infrastruc- infrastructure specifically,
  109. 3:34we again want to slice this down. So
  110. 3:37this shared infrastructure is
  111. 3:38technically one slice, but we want to
  112. 3:40further slice it down, and then work on
  113. 3:42the shared infrastructure for the shared
  114. 3:45infrastructure first. Because the domain
  115. 3:47layer is in the end the common stuff for
  116. 3:50the shared UI part and for the shared
  117. 3:53data part, because both UI and data will
  118. 3:55have a dependency to domain. And that
  119. 3:57means we need to work on domain first,
  120. 3:59because no matter if we go on with UI or
  121. 4:01data, they will both need this
  122. 4:02dependency on domain. They will both
  123. 4:04need the models that domain defines.
  124. 4:06They will both need the business logic
  125. 4:08that domain defines. So, it only makes
  126. 4:10sense to start working on domain, then
  127. 4:12on UI, like as a second step,
  128. 4:14technically you could also work on data,
  129. 4:15because UI has nothing to do with data,
  130. 4:18so
  131. 4:18what whatever you start with technically
  132. 4:20doesn't matter. But, here comes the
  133. 4:22thing.
  134. 4:22Go on with the UI, go on with working on
  135. 4:25that, because UI is something that
  136. 4:26instantly gives you something visual,
  137. 4:28something you can see. If you work on
  138. 4:30data as a second thing, it's quite hard
  139. 4:33to actually
  140. 4:34verify whether what you've built
  141. 4:36actually works. Um because you would
  142. 4:38technically have to do this with test
  143. 4:39cases, with some print line logs, but
  144. 4:42the data layer is something you can't
  145. 4:43actually just Well, you can't launch
  146. 4:46something and just click around, because
  147. 4:47well, you don't have a UI yet. Or you
  148. 4:49would have to build a dummy UI, and then
  149. 4:50you have something that you will have to
  150. 4:52delete later again. So, the easier
  151. 4:54approach is simply to to go on with the
  152. 4:56UI layer,
  153. 4:57because it's much easier to actually
  154. 4:59build some something visual you can see
  155. 5:01in the previews, what you're actually
  156. 5:02building, and that's all you need in
  157. 5:04order to verify the correctness of your
  158. 5:05UI layer. And if you then go on with the
  159. 5:08data layer as a third step, and you
  160. 5:10actually implement your DB, you
  161. 5:12implement your API access, then you can
  162. 5:14instantly verify that now, because you
  163. 5:17have the UI already that connects to it.
  164. 5:19You can instantly launch the app, and
  165. 5:21you can simply click a button that
  166. 5:22triggers a network call, and you can
  167. 5:23really see if that network call is
  168. 5:25working, if your list, for example, is
  169. 5:27populated with data. But, you can't do
  170. 5:29that if you start with data and then go
  171. 5:31on with UI.
  172. 5:32But, so far we are still at the shared
  173. 5:34infrastructure. We still haven't yet
  174. 5:35talked about any real features.
  175. 5:38So, what we want is
  176. 5:39we want to take a look at all the
  177. 5:41features here. So, this is in the end
  178. 5:42again our entire app with all the
  179. 5:44features, excluding the shared
  180. 5:46infrastructure, what we see here on the
  181. 5:47right. And all these features, or
  182. 5:49multiple of them, can at least access
  183. 5:51the shared infrastructure now.
  184. 5:53So, what we want is we want to first of
  185. 5:55all vertically slice our app
  186. 5:58into distinct features after having
  187. 6:01worked on the shared infrastructure. So,
  188. 6:03we of course want to determine which
  189. 6:04features we have. We then want to work
  190. 6:06on the shared infrastructure, and then
  191. 6:07we want to vertically slice the app
  192. 6:09feature by feature, work on the app
  193. 6:11feature by feature. But, each feature is
  194. 6:15then horizontally sliced. And each
  195. 6:17feature, we again slice that down, and
  196. 6:20we just don't approach the feature as a
  197. 6:21whole, but we say, "Okay, for a given
  198. 6:24feature, we again have a domain layer
  199. 6:26that we work on first. We again have a
  200. 6:28UI layer that we work on second. We
  201. 6:30again have a data layer that we work on
  202. 6:32last." Just for the UI, domain, and data
  203. 6:36related code for this feature that we
  204. 6:38only need inside that feature, plus what
  205. 6:41it may get from the shared
  206. 6:42infrastructure. And this is then how we
  207. 6:44really go on working on our So, for
  208. 6:46feature B, uh that is then in the end
  209. 6:48what we would work on after having fully
  210. 6:49implemented feature A here as fourth,
  211. 6:52fifth, and sixth, and so on. So, we
  212. 6:54really just build everything here in
  213. 6:56this exact order. And this is still
  214. 6:58quite abstract, I know, and that is why
  215. 7:00I will give you a practical example
  216. 7:03right here. So, this is in the end
  217. 7:04Shuff, that's the app that you learn to
  218. 7:06build in my Kotlin full-stack developer
  219. 7:09bundle. You'll find the link below. Uh
  220. 7:10but, in the end, yeah, free course
  221. 7:13bundle about building a Kotlin
  222. 7:15multiplatform app. And here I'm applying
  223. 7:17exactly that kind of slicing that I've
  224. 7:19just shown. By in the end having a
  225. 7:23module. So, this is now something that's
  226. 7:25of course dependent on the exact
  227. 7:26environment you work on. Here in Kotlin
  228. 7:28multiplatform and in native Android
  229. 7:29development each layer in this case and
  230. 7:32each feature would be its own Gradle
  231. 7:34module. So, for example, we have an auth
  232. 7:36feature consists of all three layers,
  233. 7:38well, in this case only two layers
  234. 7:39because there is no
  235. 7:41nothing about data that would be
  236. 7:43specific just to off that does not come
  237. 7:45from the shared infrastructure. But we
  238. 7:47in the end have one such module per
  239. 7:48feature. So for off, in this case it's a
  240. 7:50chat related app.
  241. 7:52We have a chat module and here also
  242. 7:54these three layers which we approach in
  243. 7:56exactly that order that I've just
  244. 7:57mentioned.
  245. 7:58For the shared infrastructure, we
  246. 8:00actually Where is that?
  247. 8:04We actually here have our core module.
  248. 8:07So core is typically how we call this
  249. 8:09when we have some shared infrastructure,
  250. 8:11some classes, functions, etc.
  251. 8:14that in the end all our features can
  252. 8:16access.
  253. 8:17And you can see we have data, domain,
  254. 8:19presentation here again. That's exactly
  255. 8:21what I've shown you here also for the
  256. 8:22shared infrastructure.
  257. 8:24In my case, I'm additionally working
  258. 8:25with a design system module.
  259. 8:27So I'm further just splitting down
  260. 8:30the UI layer kind of for our shared
  261. 8:32infrastructure into design system
  262. 8:34components so really just reusable UI
  263. 8:36components and into just presentation
  264. 8:39where the utility that is not about
  265. 8:41anything visual in this case, about any
  266. 8:43composables. So about rendering real UI
  267. 8:45components. But with these greater
  268. 8:47modules, you can then really just define
  269. 8:49exactly which kinds of dependencies you
  270. 8:51want to have. So this would be the other
  271. 8:53part. I don't want to dive too deep here
  272. 8:54into this
  273. 8:55the actual architecture behind, but much
  274. 8:57more about how you split down such an
  275. 8:59app in the first place. For a real
  276. 9:01architectural deep dive, I'd rather take
  277. 9:02a look at our mentorship program in the
  278. 9:04video's description. But all in all,
  279. 9:05this is how this could look like in the
  280. 9:07real world. I also want to share exactly
  281. 9:09why I have this split and not the the
  282. 9:13other module split where we could of
  283. 9:14course also have a presentation, domain,
  284. 9:16and data modules at the very root of our
  285. 9:18project. But you can see here at the
  286. 9:20root of the project I have a feature
  287. 9:22module with a single module per feature
  288. 9:25and then each feature is split down into
  289. 9:27clear layers. But we could of course
  290. 9:29also say that we have a presentation,
  291. 9:30domain, and data module at the root and
  292. 9:33inside these we just put the entire
  293. 9:35app's UI code in the presentation
  294. 9:37module, the entire apps data code inside
  295. 9:39the root data module, but that's a very
  296. 9:42bad approach. The approach that I have
  297. 9:44here has multiple advantages. In the
  298. 9:46end, we keep the features very isolated
  299. 9:48because one of the reasons we may want
  300. 9:49to have a multi-module architecture here
  301. 9:51is uh just reusability of certain
  302. 9:53modules.
  303. 9:54If we keep a feature isolated, and maybe
  304. 9:56an auth feature, then we can completely
  305. 9:58reuse the entire auth feature in another
  306. 10:01app that may need this exact same
  307. 10:02authentication mechanism. Also, if we
  308. 10:05would have root modules called
  309. 10:06presentation, data, domain, and we
  310. 10:08include the entire apps code in here,
  311. 10:10then that would obviously really be
  312. 10:12bloated. There would be a lot of code in
  313. 10:15those root modules. They would grow
  314. 10:16infinitely. If the app grows, these
  315. 10:18modules will grow, and that kind of
  316. 10:20defeats the purpose of having modules in
  317. 10:22the first place because one of the
  318. 10:23reasons we have that is also to speed up
  319. 10:25our Gradle build. And if these modules,
  320. 10:27so maybe only three or four modules we
  321. 10:29have for the entire app just keep on
  322. 10:31growing, then it will not only become an
  323. 10:33unmaintainable mess, but the Gradle
  324. 10:35builds will be slower and slower and
  325. 10:36slower the larger the project gets.
  326. 10:38If you're working in a team, this
  327. 10:40approach here also has the advantage
  328. 10:42that different team members can actually
  329. 10:44work on different parts of the project
  330. 10:46completely in isolation without them
  331. 10:48interfering each other, without teammate
  332. 10:50A accidentally changing code teammate B
  333. 10:52has written yesterday.
  334. 10:54That shouldn't be changed in the first
  335. 10:55place. But if you actually say, "Um
  336. 10:57Peter, you work on the chat feature."
  337. 11:00then this this architecture is making
  338. 11:02sure
  339. 11:03that these features are built in
  340. 11:04isolation.
  341. 11:05That this chat feature's data layer
  342. 11:07knows nothing about the auth feature's
  343. 11:10domain or presentation layer. And even
  344. 11:12the chat feature's presentation layer
  345. 11:13does not know anything about auth
  346. 11:15presentation. So, the architecture is
  347. 11:17intentionally built in a way that the
  348. 11:19features are completely isolated, and
  349. 11:20the only common ground is what we have
  350. 11:22in core. That is the only thing that
  351. 11:25features are able to access. And
  352. 11:27obviously, Gradle build speeds will be a
  353. 11:29lot faster with this approach since
  354. 11:31Gradle can just paralyze certain builds
  355. 11:33here when multiple changes are being
  356. 11:35made in isolated feature modules, then
  357. 11:38all these modules can really be built in
  358. 11:40parallel. You really benefit from faster
  359. 11:42builds there, especially for large
  360. 11:43projects. So, all in all, this is what
  361. 11:45has been my preferred architecture for
  362. 11:47the past 4 years or so. Those of you who
  363. 11:50got my courses will know this. I'm still
  364. 11:52sticking to this. This has never
  365. 11:53backfired for me. This has always
  366. 11:55worked. Get into it. Learn it.
  367. 11:57But, this is in the end how I slice down
  368. 11:59my
  369. 12:00So, as a summary again, first of all,
  370. 12:02you want to have vertical slices. You
  371. 12:03want to think about which features does
  372. 12:05the app consist of? And then, per
  373. 12:07feature and the shared infrastructure, I
  374. 12:09kind of consider as a feature, as
  375. 12:11something we would have to work on
  376. 12:12first. Then, per shared infrastructure
  377. 12:14or per feature after all, we want to
  378. 12:16horizontally slice that. So, by layer,
  379. 12:19we first of all work on the domain
  380. 12:21layer, then UI, and then data. And if
  381. 12:23this is confusing you,
  382. 12:25I get that. It's a lot to learn and this
  383. 12:27is just something you have to practice.
  384. 12:29You have to build yourself in a project.
  385. 12:31You have to really understand the ins
  386. 12:33and outs of, especially in terms of AI,
  387. 12:36where an It's very easy for an agent to
  388. 12:38just strongly accelerate on a wrong
  389. 12:40foundation for your app. So, if
  390. 12:41architecture, system design, the modern
  391. 12:44Android tech stack is something you want
  392. 12:45to get super super deep into and become
  393. 12:48a really desirable Android developer,
  394. 12:50and then also learn how you can
  395. 12:51accelerate that with AI after having
  396. 12:53gained the technical fundamentals. Then,
  397. 12:55take a look at our senior app developer
  398. 12:57mentoring. We really help you grow to a
  399. 12:59senior level, be it as an Android
  400. 13:01developer, be it as a Kotlin
  401. 13:02multi-platform developer. We will help
  402. 13:04you both technically as well as on the
  403. 13:06AI side to then really speed up
  404. 13:08everything. Link is below. Take a look
  405. 13:10at it. Apply. And then, we're going to
  406. 13:12have a chat very soon. Thanks for
  407. 13:13watching. I will see you back in the
  408. 13:15next video. Have an amazing rest of your
  409. 13:16week. Bye-bye.
  410. 13:22>> [music]
  411. 13:25>> Mhm.
  412. 13:28>> [music]
  413. 13:29>> Mhm.
  414. 13:31Mhm.
  415. 13:33Mhm.

About this transcript

This page contains the full transcript of Vertical vs. Horizontal Slicing - The ONLY Right Way to Split Down Your App by Philipp Lackner, generated from the public captions YouTube serves with the video. The transcript has 2,710 words across 415 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.