In a monolithic architecture the logical architecture may be modular but typically implementation view(deployable unit) is a single war/jar . While to start with monolithic architecture is simple to code over a period of time change into systems which are too complex for any developer to understand with lot of intermodule interdepencies and also very poor fault isolation capabilities at run time.
Note the software architecture has a
- logical view - software elements/modules created by developer. eg package / classess in java
- implementatino view - the output of build system, eg war/ jar..
- process view - compents at runtime
- deployment - how the process are mapped to machines
Monolithic architecture has compelling advantages becuase of which many application are developed using the monolithic architecture.
- Simple to develop
- IDE and other development tools are focussed on building single application...
- Simple to deploy
- Easy to scale, (put deploy multiple instances behind a load balancer)
- Keeps transactions acid is simple as different logical modules will all be updating the same database.
How over a period of time in large complex applications monolithic architecture becomes unmatainable no matter how desciplined the software team is
- The logical modules in code are interdepdent , code based becomes incrementlally more complex and becomes increasingly incomprehensivble and becomes too complex for any developer to understand
- Making changes becomes very tough as what impact the code change or change of table schema will have on different logical modules becomes increasingly hard to predict. Since of impact of change is not well understood, hence testing takes a long time. Hence speed of software delivery suffers.
- Many monolith developers commiting to code base can be an issue in CI /CD model. If feature branching is used then handling merges becomes a headache.
- Large applications slow down ide as well.
- Edit, build ,run cycle can take a long time.
- Application startup time also increases. This is of particular concern when the number of instances are bing autoscaled by a load balancer.
- Continuous deployment becomes tough , where deploying changes many times during business hours is possible...,
- amazon.com has deployed a change to prod every 11 seconds without ever impacting user...
- CPU intesive modules(image processing) are co deoployed with memory intensive modules..
- Fault isolation is a massive issue in monolithic applicaations
- Extremely hard to move away from technology stack / software version. Over a period of time software version and tech stack become obsolete yet org is forced to use it. In a monolithic architecture the intial choices severly constrain the system
Microservices architecture to the rescue.
The high level definition of microservices is an architectural style that functionally decomposes an application into set of loosely coupled services which talk via api .
- Each service exposes clearly defined api layer, which is a boundry that must not be violateed ,ie a service can't bypass api of another service and and access its database directly .
- Each service has its own datastore.
- each service having its own datastore is an idea which is central to microservices architecture.
- this ensures loose development time and run time coupling between services
- at development time teams would not have co-ordination issues with each other.
- At run time dead locks in one service should not affect another service.
- note that seprate db does not necessarily mean seprate db server.
- The services are isolated at developent , deployment and runtime, even db is separated
- Each service can be independtly
- Developed
- Software development gets parallelized as different autonomous teams can potentially handle different services without interacting with each other.
- Tested,
- Deployed
- Scaled,
- Developed
Advantages of microservices architecture
- Enables continous deployment of large applications
- Services are small and easily maitained.
- services are independlty deployable(no depenency on another team), scalable,
- easty to experiment new technology
- devleopment teams can be autonomous and loosely couped...
- much better falul isolation
- egg can be structured in into small two pizaa teams
- each service is relatively small and hence code is easier to understand
- small code does not slow down ide..
- service startup time for a small service is much faster than a large monolith..
- each service can be deployed on hardware which is best suited for its requirements..
- no long term commitment to tech stack..you are not constrained by past descions...
Disadvantages of microservices architecture
- with small team sizes and smaller projects microservices architecture will introduce more complexities.
- it may be better to choose a modular monolithic architectures with logical boundries (ever thing will continue to be in the same process) . the db of different logical modueles could be different schemas in the same db instance. read more about a loosely coupled monolith approach here https://www.youtube.com/watch?v=VGShtGU3hOc
- finding right set of services can be challenging
- if u decompose incorrectly you get a distributed monolith which has disadv of both microservice and monolith.
- deploying features which span mult servies can be challenging
- over head of ipc , calls are much simpler...
- dealing with partial faillure, remote servie may not be avaliable..
- transactions become hard to manage as multile databases..
- querying database when a query spans databases becomes complex...
- you would need deployment tools like netflix spinnaker
- off the shelfl paas like pivotal cloud foundry or redhapt openshift
- docker orchestration paltform like kuberntes or dockerswarm
- diagnosign problems via looking at logs can be issue as request is bouncing off multiple services...