Skip to content

Commit d7df8fa

Browse files
authored
Post: Custom Common Libraries For Integration Services (#115)
1 parent d8d8242 commit d7df8fa

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed
Loading
Loading
Loading
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Custom Common Libraries For Backend Services
2+
3+
Discover the best practices and considerations for commonizing aspects of software development, including custom libraries and business logic. Learn when commonization enhances efficiency and when customization is essential for project success.
4+
5+
![](assets/thumbnail.png)
6+
7+
Authors: Furkan Aksin
8+
Date: unpublished
9+
Category: backend
10+
11+
tags: custom, integration, services, commonize, backend, logging, error, handling, libraries, library
12+
13+
---
14+
15+
## **Introduction**
16+
17+
Common libraries are like toolboxes for developers, helping simplify tasks, reuse code, decrease code duplication, making projects consistent across multiple service aspects and keep them organized. They're essential for making coding easier and projects more manageable.
18+
19+
In this post, we go through the importance of custom common libraries in backend development, exploring their benefits, structures, and considerations. We'll discuss common library structures, explore commonized capabilities beyond it, examine scenarios where common libraries may not be suitable, highlight the advantages of using custom libraries, and consider their disadvantages and key considerations. Finally, we'll conclude with insights on effectively leveraging custom common libraries in software development.
20+
21+
---
22+
## **Why Custom Common Libraries?**
23+
24+
Before diving into the specifics of custom libraries, let's briefly explore why custom common libraries are valuable assets in modern development before diving into the details in next sections:
25+
26+
1. **Avoid Code Duplication**: By centralizing common functionalities in a custom library, developers can avoid duplicating code across projects.
27+
2. **Consistency**: By encapsulating common logic within a reusable library, you ensure consistency across your projects. This consistency simplifies maintenance and reduces the likelihood of errors.
28+
3. **Abstraction**: Libraries abstract away low-level implementation details, allowing developers to focus on business logic rather than intricate networking configurations.
29+
4. **Flexibility**: Custom libraries can be tailored to suit the specific requirements of your project, offering a level of flexibility that generic solutions may lack.
30+
5. **Enhanced Security**: Implementing standardized security measures within the library ensures that all API communications adhere to best practices, minimizing vulnerabilities.
31+
32+
![](assets/library.png)
33+
34+
---
35+
36+
## **Common Libraries Structures**
37+
38+
Custom libraries can be structured in various ways to organize their functionality effectively. For instance, they might follow a package naming convention like "com.example.custom" with subpackages such as "logging," "rest," and "tls," each handling specific functionalities. Alternatively, libraries could adopt a naming scheme like "example-captcha," and "example-communication," where each name reflects a distinct aspect or feature set of the library. The choice of structure depends on factors like the library's scope, the complexity of its functionalities, and the preferences of the development team.
39+
40+
#### ***First Approach Example***
41+
```
42+
.
43+
└── com
44+
└── project
45+
└── custom
46+
└── src
47+
├── main
48+
│ ├── java
49+
│ │ └── com
50+
│ │ └── example
51+
│ │ └── custom
52+
│ │ ├── logging
53+
│ │ │ └── ...
54+
│ │ ├── rest
55+
│ │ │ └── ...
56+
│ │ └── tls
57+
│ │ └── ...
58+
│ └── resources
59+
│ └── ...
60+
└── test
61+
└── ...
62+
```
63+
64+
#### ***Second Approach Example***
65+
```
66+
.
67+
└── example-events
68+
├── example-captcha
69+
├── example-communication
70+
│ └── src
71+
│ ├── main
72+
│ │ ├── java
73+
│ │ │ └── com
74+
│ │ │ └── example
75+
│ │ │ └── communication
76+
│ │ │ ├── provider # Provider classes
77+
│ │ │ │ └── ...
78+
│ │ │ ├── config # Configuration classes
79+
│ │ │ │ └── ...
80+
│ │ │ ├── models # Model classes
81+
│ │ │ │ └── ...
82+
│ │ └── resources # All resource files except core classes
83+
│ │ └── ...
84+
│ └── test # JUnit test files
85+
│ └── ...
86+
└── example-token
87+
88+
```
89+
90+
91+
---
92+
## **Beyond Common Libraries: Commonized Capabilities**
93+
94+
In addition to logging, timeout management, and TLS configuration, several other capabilities can be commonized in custom libraries. General error handling strategies, for instance, can be standardized to ensure consistent responses to various failure scenarios, enhancing robustness across services.
95+
96+
Furthermore, rate limiting and circuit breaking mechanisms can be integrated to manage service dependencies effectively and prevent cascading failures. Authentication and authorization mechanisms can also be abstracted to simplify integration with authentication providers and enforce access control policies consistently.
97+
98+
By encapsulating these common functionalities within custom libraries, developers can accelerate development, improve maintainability, and ensure adherence to best practices across their projects.
99+
100+
### **Areas of Common Libraries**
101+
102+
Let's say we're building a web application that needs to communicate with various external services, log important events, handle user authentication tokens, and manage event notifications. We can leverage common libraries for each of these tasks:
103+
104+
- **Communication:** We use a communication library to simplify making HTTP requests to external APIs. We can use simplified RestTemplate instances in there. For example, we can use the library to send requests to a payment gateway or retrieve data from a third-party service.
105+
```yaml
106+
# Communication Configuration
107+
communication:
108+
endpoint: "https://api.example.com"
109+
timeout: 5000
110+
headers:
111+
Content-Type: "application/json"
112+
Authorization: "Bearer {TOKEN}"
113+
```
114+
115+
- **Logging:** A logging library helps us track important events and debug issues in our application. For instance, we can use it to log user login attempts, errors encountered during API calls, or critical system events.
116+
```yaml
117+
# Logging Configuration
118+
logging:
119+
level: "debug"
120+
format: "json"
121+
file_path: "/var/log/myapp.log"
122+
```
123+
- **Eventing:** Eventing libraries enable us to publish and subscribe to events within our application or across different services. We can use it to trigger actions based on user interactions, such as sending an email confirmation after a successful purchase or updating user preferences.
124+
```yaml
125+
# Eventing Configuration
126+
eventing:
127+
topics:
128+
- name: "user_actions"
129+
description: "Events related to user actions"
130+
subscribers:
131+
- url: "https://webhook.example.com"
132+
auth:
133+
username: "user"
134+
password: "password"
135+
```
136+
- **Token Management:** With a token management library, we can securely generate, validate, and manage user authentication tokens. For instance, we can use it to issue JSON Web Tokens (JWTs) for user authentication or generate access tokens for API authorization.
137+
```yaml
138+
# Token Management Configuration
139+
token_management:
140+
jwt:
141+
secret: "my_secret_key"
142+
expiry: 3600 # 1 hour
143+
```
144+
145+
By incorporating these common libraries into our application, we simplify development, promote code reuse, and ensure consistency in how we handle communication, logging, eventing, and token management.
146+
147+
### **Release Cycle of Utility Libraries**
148+
149+
In managing utility libraries, sticking to a regular release schedule is important. Unlike integration services, these libraries can have their own release timetable. It's better not to use snapshot versions because they can cause problems. In using snapshot versions, it can lead to unpredictability and potential conflicts, making it harder for developers to maintain a stable environment. By keeping the release cycle separate from integration services, developers can avoid issues and adapt to changes more easily. This way, they can fix bugs and add new features without causing disruptions.
150+
151+
---
152+
## **When Not to Use Common Libraries?**
153+
154+
Despite the benefits of common libraries, there are instances where specialized backend requirements warrant custom solutions. Here are scenarios where common libraries may not be the best fit:
155+
156+
- Highly specialized business logic needs
157+
- Unique platform constraints
158+
- API-specific error handling
159+
- Performance optimization requirements
160+
- Regulatory compliance demands
161+
162+
![](assets/purposes.png)
163+
---
164+
## **Advantages of Using Custom Libraries**
165+
166+
The adoption of custom libraries offers several advantages and examples for them:
167+
168+
1. **Improved Productivity**: Streamlined integration processes reduce development time and effort, enabling teams to focus on core functionality and avoid such code duplications.
169+
- In a microservices-based platform, developers utilize a custom library to abstract away complexities of making API calls to various external services (e.g., payment gateways, inventory management systems, shipping providers).
170+
- This abstraction allows for quick integration of services without manual implementation of communication logic, reducing development time and effort.
171+
2. **Enhanced Maintainability**: Centralized communication logic simplifies maintenance tasks and promotes code reuse across projects.
172+
- If a software company develops multiple products requiring integration with third-party APIs (e.g., user authentication, email notifications, file storage).
173+
- By centralizing communication logic in a custom library, the company ensures consistency across all products, simplifying maintenance and promoting code reuse.
174+
3. **Debugging and Monitoring**: Comprehensive logging capabilities facilitate debugging and monitoring of API interactions, aiding in troubleshooting.
175+
- An enterprise application interacts with various external APIs for processing orders, managing inventory, and generating reports.
176+
- Common library's logging capabilities provide detailed insights into request/response flows, timing, headers, payloads, and response statuses, aiding in debugging and monitoring efforts.
177+
- For instance, if an order fails, developers can analyze logs to identify issues with the API call and quickly resolve them.
178+
4. **Scalability**: Custom libraries can be tailored to accommodate evolving project requirements and scale alongside the application.
179+
- A startup developing a mobile app connecting users with local service providers experiences growth in user base and features.
180+
- With common library, as API integrations become more numerous and complex, the library can scale alongside the application, accommodating evolving requirements efficiently.
181+
5. **Security**: Built-in security features ensure secure communication with external APIs, mitigating risks associated with data breaches and unauthorized access.
182+
- In a financial application handling sensitive user data, a custom communication library ensures secure communication with external banking APIs.
183+
- The library's built-in security features, such as TLS encryption and certificate validation, safeguard against data breaches and unauthorized access, maintaining the integrity and confidentiality of user information.
184+
185+
## **Disadvantages and Considerations**
186+
187+
While custom libraries offer numerous benefits, it's essential to consider potential drawbacks:
188+
189+
1. **Dependency Management**: Introducing additional dependencies increases the complexity of the project's dependency tree and requires careful management.
190+
2. **Learning Curve**: Developers unfamiliar with the custom library may require time to understand its implementation and configuration.
191+
192+
---
193+
## **Conclusion**
194+
195+
In the realm of software integration, effective communication is paramount. Custom libraries streamline the integration process, offering a robust foundation for building reliable and secure connections with external APIs. By leveraging the features and flexibility of custom libraries, developers can accelerate development, enhance maintainability, and ensure seamless interoperability across their projects.
196+
197+
---

0 commit comments

Comments
 (0)