Skip to content

Commit 1a08b73

Browse files
committed
docs: update monolithic architecture
1 parent 0f37b4e commit 1a08b73

File tree

4 files changed

+83
-94
lines changed

4 files changed

+83
-94
lines changed

Diff for: monolithic-architecture/README.md

+80-79
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
---
2-
title: "Monolithic Ecommerce App: A Cohesive Application Model"
3-
shortTitle: Monolithic Ecommerce
4-
description: "Explore the Monolithic Ecommerce application structure, its design intent, benefits, limitations, and real-world applications. Understand its simplicity and practical use cases."
2+
title: "Monolithic Architecture in Java: A Cohesive Application Model"
3+
shortTitle: Monolithic Architecture
4+
description: "Explore the Monolithic Architecture application structure, its design intent, benefits, limitations, and real-world applications. Understand its simplicity and practical use cases."
55
category: Architectural
66
language: en
77
tag:
8-
- Cohesion
8+
- Architecture
9+
- Cohesion
10+
- Encapsulation
11+
- Layered architecture
12+
- Modularity
913
---
1014

11-
## Monolithic-Ecommerce App
12-
* A Monolithic Ecommerce example to showcase Monolithic Architecture
15+
## Also known as
16+
17+
* Single-tier architecture
18+
* Monolith
1319

1420
## The Intent of Monolithic Design pattern
15-
> the Monolithic Design Pattern structures an application as a single, cohesive unit where all components—such as business logic, user interface, and data access are tightly integrated and operate as part of a single executable.
21+
22+
Encapsulate all the functionality of an application within a single, cohesive codebase.
1623

1724
## Detailed Explanation of the Monolithic Architecture
18-
Real-world Example
19-
> A traditional E-commerce website is the most straightforward example for a monolithic application as it is comprised of a catalogue of products, orders to be made, shopping carts, and payment processes that are all inseperable of each other.
20-
21-
In Plain words
22-
>The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.
23-
24-
GeeksforGeeks states
25-
> Monolithic architecture, a traditional approach in system design, which contains all application components into a single codebase. This unified structure simplifies development and deployment processes, offering ease of management and tight integration. However, because of its rigidity, it is difficult to scale and maintain, which makes it difficult to adjust to changing needs.
26-
27-
Why use MVC for a Monolithic Application ?
28-
>The Model-View-Controller (MVC) pattern is not inherently tied to microservices or distributed systems. It's a software design pattern that organizes the codebase by separating concerns into three distinct layers:
29-
>* Model
30-
>* View
31-
>* Controller
32-
>
33-
> this also helps maintain the principles of a Monolithic Architecture which are:
34-
>
35-
> Simple to
36-
>* Develop
37-
>* Test
38-
>* Deploy
39-
>* Scale
40-
>
41-
42-
Architecture diagram
43-
44-
![Model-View-Controller Architecture Diagram](./etc/mvc-architecture-diagram.png)
45-
46-
## We can clearly see that this is a Monolithic application through the main class
47-
This is a simplified version of the main application that shows the main interaction point with the CLI and how a user is registered
25+
26+
Real-world example
27+
28+
> An analogous real-world example of the Monolithic Architecture pattern is a department store. Just like a monolithic Java application, a department store hosts all product categories, sales, storage, and customer services within a single, large building. It simplifies shopping by consolidating everything under one roof, making operations straightforward and easy to manage. However, expanding or rearranging specific departments becomes increasingly challenging over time, similar to how scaling individual functionalities within a monolithic system can become complex and cumbersome.
29+
30+
In plain words
31+
32+
> The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.
33+
34+
Wikipedia says
35+
36+
> In software engineering, a monolithic application is a single unified software application that is self-contained and independent of other applications, but typically lacks flexibility. There are advantages and disadvantages of building applications in a monolithic style of software architecture, depending on requirements. Monolith applications are relatively simple and have a low cost but their shortcomings are lack of elasticity, fault tolerance and scalability.
37+
38+
Mind map
39+
40+
![Monolithic Architecture Mind Map](./etc/monolithic-architecture-mind-map.png)
41+
42+
Flowchart
43+
44+
![Monolithic Architecture Flowchart](./etc/monolithic-architecture-flowchart.png)
45+
46+
## Programmatic Example of Monolithic Architecture in Java
47+
48+
This is a simplified version of the main application, demonstrating how a monolithic architecture can be implemented. Here, all the essential services—such as user management (`UserCon`), product management (`ProductCon`), and order processing (`OrderCon`) — are tightly integrated within a single executable Java application. The CLI provides a straightforward user interaction point where operations like user registration, adding products, and placing orders are handled.
49+
4850
```java
4951
@SpringBootApplication
5052
public class EcommerceApp implements CommandLineRunner {
@@ -105,47 +107,46 @@ public class EcommerceApp implements CommandLineRunner {
105107

106108
}
107109
```
108-
### We can clearly reach the conclusion that all of these classes reside under the same module and are essential for each other's functionality, this is supported by the presence of all relevant classes as parts of the main application class.
109-
110-
## When should you resort to a Monolithic Architecture ?
111-
>* An enterprise Starting off with a relatively small team
112-
>* Simplicity is the most important factor of the project
113-
>* Maintaining less entry points to the system is cruical
114-
>* Prototyping ideas
115-
>
116-
## Pros & Cons of using Monolithic Architecture
117-
>### Pros:
118-
>* Simple Development: Easy to develop and deploy.
119-
>* Unified Codebase: All code in one place, simplifying debugging.
120-
>* Better Performance: No inter-service communication overhead.
121-
>* Lower Costs: Minimal infrastructure and tooling requirements.
122-
>* Ease of Testing: Single application makes end-to-end testing straightforward.
123-
> * This is also assisted by the MVC structure employed in this example.
124-
>### Cons:
125-
>* Scalability Issues: Cannot scale individual components.
126-
>* Tight Coupling: Changes in one area may impact the whole system.
127-
>* Deployment Risks: A single failure can crash the entire application.
128-
>* Complex Maintenance: Harder to manage as the codebase grows.
129-
>* Limited Flexibility: Difficult to adopt new technologies for specific parts.
130-
131-
## Real-World Applications of Monolithic architecture Pattern in Java
132-
>* E-Commerce Platforms
133-
>* Content Management Systems (CMS)
134-
>* Banking and Financial Systems
135-
>* Enterprise Resource Planning (ERP) Systems
136-
>* Retail Point of Sale (POS) Systems
110+
111+
In this example, the core business functionalities are closely interconnected, sharing common resources and residing within the same codebase. This approach simplifies initial application development, testing, and deployment, as each component can easily access the others directly without the overhead of inter-service communication. However, as the application grows, scaling individual components independently becomes more challenging, highlighting the key trade-off inherent in the monolithic architecture.
112+
113+
## When to Use the Monolithic Architecture in Java
114+
115+
* Suitable for small to medium-sized applications where simplicity, cohesive development, and ease of deployment outweigh scalability and flexibility requirements.
116+
* Applicable in contexts where initial rapid development and ease of testing are prioritized.
117+
118+
## Real-World Applications of Monolithic Architecture in Java
119+
120+
* Early-stage Java web applications developed using frameworks like Spring MVC, Java EE (Servlets/JSP), or frameworks like Play.
121+
* Traditional Java enterprise applications packaged and deployed as WAR or EAR files on application servers such as Apache Tomcat, Jetty, or WildFly.
122+
* Standalone Java applications and desktop applications packaged as single executable JAR files.
123+
124+
## Benefits and Trade-offs of Monolithic Architecture
125+
126+
Benefits:
127+
128+
* Simpler to develop, test, and deploy as the application is a single unit.
129+
* Easier debugging and performance monitoring due to the single unified runtime.
130+
* Typically faster initial development and straightforward management of dependencies.
131+
132+
Trade-offs:
133+
134+
* Poor scalability and potential performance bottlenecks as the application grows.
135+
* Limited modularity, leading to increased complexity and harder maintainability over time.
136+
* Slow deployments and updates due to a single large codebase.
137+
* Difficult to scale individual functionalities independently.
138+
139+
## Related Patterns
140+
141+
* Microservices Architecture: Breaks down a monolithic application into independently deployable services, directly addressing the scalability and maintainability limitations of monoliths.
142+
* [Layered Architecture](https://java-design-patterns.com/patterns/layered-architecture/): Often used internally within monoliths to provide clear separation between presentation, business logic, and persistence layers.
137143

138144
## References
139-
>* [GeeksforGeeks](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
140-
>* [Wikipedia](https://en.wikipedia.org/wiki/Monolithic_application)
141-
>* [vFunction](https://vfunction.com/blog/what-is-monolithic-application/#:~:text=A%20traditional%20e%2Dcommerce%20platform,inseparable%20components%20of%20the%20system.) Blog post
142-
>* [Microservices.io](https://microservices.io/patterns/monolithic.html)
143-
>* [IBM](https://www.ibm.com/think/topics/monolithic-architecture)
144-
>#### References used to create the code
145-
>* [Mockito](https://site.mockito.org/) -Testing
146-
>* [Junit](https://junit.org/junit5/docs/current/user-guide/) -Testing
147-
>* [Springboot](https://docs.spring.io/spring-boot/index.html) -Web Application Initiation (implemented but not utilized in this example)
148-
>* [Sprint Data Jpa](https://docs.spring.io/spring-data/jpa/reference/index.html) -Database connection
149-
>* [Lombok](https://projectlombok.org/) -Simplifying Classes
150-
>* [Log4j](https://logging.apache.org/log4j/2.x/index.html) -Capturing Logs
151-
>* [H2 Databse](https://www.h2database.com/html/tutorial.html) -Efficient, Simple, Dynamic Databse
145+
146+
* [Building Microservices](https://amzn.to/3UACtrU)
147+
* [Fundamentals of Software Architecture: An Engineering Approach](https://amzn.to/4cx4A2N)
148+
* [Monolithic Architecture - System Design (GeeksforGeeks)](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
149+
* [Monolithic Application (Wikipedia)](https://en.wikipedia.org/wiki/Monolithic_application)
150+
* [Pattern: Monolithic Architecture (Microservices.io)](https://microservices.io/patterns/monolithic.html)
151+
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
152+
* [What Is Monolithic Architecture? (IBM)](https://www.ibm.com/think/topics/monolithic-architecture)
Loading
Loading

Diff for: monolithic-architecture/src/test/java/com/iluwatar/monolithic/MonolithicAppTest.java

+3-15
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ void testPlaceOrderUserNotFound() {
9595
new OrderController(mockOrderRepo, mockUserRepository, mockProductRepository);
9696

9797
Exception exception =
98-
assertThrows(
99-
NonExistentUserException.class,
100-
() -> {
101-
orderCon.placeOrder(1L, 1L, 5);
102-
});
98+
assertThrows(NonExistentUserException.class, () -> orderCon.placeOrder(1L, 1L, 5));
10399

104100
assertEquals("User with ID 1 not found", exception.getMessage());
105101
}
@@ -119,11 +115,7 @@ void testPlaceOrderProductNotFound() {
119115
new OrderController(mockOrderRepository, mockUserRepository, mockProductRepository);
120116

121117
Exception exception =
122-
assertThrows(
123-
NonExistentProductException.class,
124-
() -> {
125-
orderCon.placeOrder(1L, 1L, 5);
126-
});
118+
assertThrows(NonExistentProductException.class, () -> orderCon.placeOrder(1L, 1L, 5));
127119

128120
assertEquals("Product with ID 1 not found", exception.getMessage());
129121
}
@@ -196,11 +188,7 @@ void testPlaceOrderInsufficientStock() {
196188
new OrderController(mockOrderRepository, mockUserRepository, mockProductRepository);
197189

198190
Exception exception =
199-
assertThrows(
200-
InsufficientStockException.class,
201-
() -> {
202-
orderCon.placeOrder(1L, 1L, 5);
203-
});
191+
assertThrows(InsufficientStockException.class, () -> orderCon.placeOrder(1L, 1L, 5));
204192
assertEquals("Not enough stock for product 1", exception.getMessage());
205193
}
206194

0 commit comments

Comments
 (0)