LongCut logo

How to Write Scalable, Production-Ready Code

By Immaculate Coder

Summary

## Key takeaways - **Architecture Prevents Maintenance Nightmares**: Touching one part of a poorly architected project breaks many unrelated other parts, making it unpleasant to work on. [01:05] - **Poor Structure Slows Onboarding**: When code is big enough and lacks structure, explaining it to a new developer is hard, taking lots of effort and time for them to contribute. [01:17] - **Skipping Architecture Slows You Long-Term**: You might move fast initially without thinking about architecture, but on the long run it will make you slower not faster. [01:28] - **Layered Architecture Unidirectional Dependencies**: In layered architecture, code is organized into presentation layer for UI and API, service layer for business logic, data access layer for databases, with unidirectional dependencies from presentation to service to data access. [02:23] - **Hexagonal Inverts Data Dependencies**: Hexagonal architecture isolates core application logic from external concerns using dependency inversion principle, inverting the dependency from service layer to data access layer for flexibility in switching databases. [03:29] - **Microservices Enable Team Independence**: Microservices split software into smaller services like product service, order service, payment service, and inventory service that communicate via APIs or messages, allowing teams to develop, deploy, and scale independently. [04:22]

Topics Covered

  • Architecture Prevents Maintenance Nightmares
  • Layered Architecture Enforces Unidirectional Dependencies
  • Hexagonal Inverts Dependencies for Flexibility
  • Microservices Enable Team Independence

Full Transcript

there are many aspects to writing production ready code but it all starts with a solid foundation architecture without write architectural decisions even the best written code will struggle

to scale in this guide we'll break down the key principles of building software that doesn't just work today but thrives as it grows if this is your first time on my channel and you don't know who I

am I'm just a fellow software engineer on a mission to discover the most elite way to build software I talk about topics such as architecture design testing and modern best practices based

on my experience and the extensive research I do I deliver to you short Snippets of valuable software knowledge if you like more of that hit the Subscribe button below and let's proceed

first of all why should you even care why can't you just ignore all of this and proceed with your life writing code the way you do now here are four reasons why this will come back to bite you

number one your code will become a maintenance nightmare we've all been through working on a project object when touching one part of it breaks so many unrelated other parts it just doesn't

make any sense and it's so unpleasant to work on number two collaboration will be painful when your code is big enough and a new developer wants to join it's so hard to explain to him the structure of

the code if you don't even have any thus unboarding him will take a lot of effort and it will take a lot of time for him to be able to contribute number three you'll struggle to make progress maybe

you didn't even think about architecture because you just want to move fast however on the long run you will notice that this will make you slower not faster number four your growth as a

developer will suffer Engineers who understand architecture don't just write code they build systems if you want to work on a large scale project or move into senior roles you need to master

this now that you are convinced architecture is important what is it truly and how can you start applying It software architecture is a fancy term that just means means the way you

organize your code so it's easy to change maintain and scale as your project grows you can go and invent your own architecture and experiment with it for a decade or so or you can just learn

from Battle tested architectures used by top engineers in the industry here are some of the most widely used and proven software architectures layered architecture this one is a classic

architecture that's easy to understand and apply code is Simply Organized into layers each handling a specific response responsibility for example we have a presentation layer handles UI and API

endpoints service layer business logic lives here data access layer interacts with databases and the most important thing to note here is the line of dependency because we will compare this

with other architectures let's take an example of adding an order to understand this better first you will have a controller that handles the postest API to add order in the presentation layer

this will use a service we create in the a service layer called order persistor for example which will in turn use another service that interacts with the database directly called order

repository as you can see above the dependency line is unidirectional from presentation to service to data access layer this might be a good start but

it's a bit rigid and won't scale best that is because as you have noticed you have a direct dependency between service layer and data access layer this won't allow you to easily switch databases for

example that's where the hexagonal architecture is stepped in it solves this issue using a principle called dependency inversion principle hexagonal architecture changes dab by isolating

your core application logic from external concerns so you see the line in here from the service layer to the data access layer it is inverted yep that's why the principle is called dependency

inversion principle that's much better because now you have better flexibility in switching databases or any data access detail without affecting the

service layer when you start applying that you will have great scalable service you're working on but once you are a great success you will start adding more and more software Engineers

to the team and once you're big enough you'll split into multiple teams once you are in teams coordinating between each other is harder it's preferable for

each team to be able to develop deploy and scale independently but you are still all working on the same product so how can you you achieve that it's called microservices architecture we split the

software into smaller services that each team will work on one or couple of ones those microservices will communicate with each other using apis or messages let's say you're building an e-commerce

platform with microservices so for example product service handles product listings details and availability order service manages order creation status

updates and order history payment service handles Payment Processing inventory service manages stock levels and availability and so on and so forth a question might pop into your mind what

architecture do I follow in each microservice then well you can still follow hexagonal architecture in each microservice it works great architectures aren't limited to the ones

I mentioned but this is a great start for you if you'd like to learn more about this topic I recommend reading the book clean architecture by Robert C Martin also if you're interested in learning how to apply exagonal

architecture I have a program called Essentials program where I assign participants a project to work on and guide them to apply the exagonal architecture in this project along with

super important other principles the link is in the description below just like building a house you wouldn't start by randomly stacking bricks or installing Windows before the walls are

up you need a good plan to make sure the house is strong easy to live in and can be expanded later on similarly a good architecture Mak software strong easy to

work with and ready for growth if you don't plan ahead you'll regret it when things start falling apart

Loading...

Loading video analysis...