Skip to content

Commit acb40e1

Browse files
committed
docs: update microservices distributed tracing
1 parent 9de12ea commit acb40e1

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

Diff for: microservices-distributed-tracing/README.md

+35-23
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22
title: "Microservices Distributed Tracing Pattern: Enhancing Visibility in Service Communication"
33
shortTitle: Distributed Tracing in Microservices
44
description: "Learn how the Distributed Tracing pattern enhances visibility into service communication across microservices. Discover its benefits, implementation examples, and best practices."
5-
category: Structural
5+
category: Architectural
66
language: en
77
tag:
8-
- Scalability
8+
- Cloud distributed
9+
- Microservices
10+
- Resilience
11+
- Scalability
12+
- Observability
13+
- System health
914
---
1015

1116
## Intent of Microservices Distributed Tracing Design Pattern
1217

13-
Distributed tracing aims to monitor and track requests as they flow through different services in a microservices architecture, providing insights into performance, dependencies, and failures.
18+
Provide a mechanism to trace and correlate requests as they traverse multiple microservices in a distributed system, enabling end-to-end visibility and easier troubleshooting.
1419

1520
## Also known as
1621

1722
* Distributed Request Tracing
18-
* End-to-End Tracing
23+
* End-to-End Microservice Tracing
1924

2025
## Detailed Explanation of Microservices Distributed Tracing Pattern with Real-World Examples
2126

2227
Real-world example
2328

24-
> In an e-commerce platform, distributed tracing is used to track a customer's request from the moment they add an item to the cart until the order is processed and shipped. This helps in identifying bottlenecks, errors, and latency issues across different services.
29+
> Imagine an online food delivery platform where one microservice handles user orders, another manages restaurant menus, and yet another coordinates courier assignments. When a user places an order, the request travels through all three services in sequence. By implementing distributed tracing, each service attaches a trace identifier to its logs. This allows the operations team to follow the journey of a single order across the entire pipeline, identify any delays along the way, and quickly pinpoint which service is causing the bottleneck or experiencing an error.
2530
2631
In plain words
2732

@@ -31,10 +36,13 @@ Wikipedia says
3136

3237
> Tracing in software engineering refers to the process of capturing and recording information about the execution of a software program. This information is typically used by programmers for debugging purposes, and additionally, depending on the type and detail of information contained in a trace log, by experienced system administrators or technical-support personnel and by software monitoring tools to diagnose common problems with software.
3338
34-
## Programmatic Example of Microservices Distributed Tracing in Java
39+
Sequence diagram
40+
41+
![Microservices Distributed Tracing Sequence Diagram](./etc/microservices-distributed-tracing-sequence-diagram.png)
3542

43+
## Programmatic Example of Microservices Distributed Tracing in Java
3644

37-
This implementation shows how an e-commerce platform's `OrderService` interacts with both `PaymentService` and `ProductService`. When a customer places an order, the `OrderService` calls the `PaymentService` to process the payment and the `ProductService` to check the product inventory. Distributed tracing logs are generated for each of these interactions and can be viewed in the Zipkin interface to monitor the flow and performance of requests across these services.
45+
This implementation shows how an e-commerce platform's `OrderService` interacts with both `PaymentService` and `ProductService`. When a customer places an order, the `OrderService` calls the `PaymentService` to process the payment and the `ProductService` to check the product inventory. By adding distributed trace instrumentation (usually via libraries like Spring Cloud Sleuth or OpenTelemetry), each service attaches trace context to outgoing requests and logs. These logs can then be viewed in the Zipkin interface (or other tracing tools, such as Jaeger) to observe the entire flow of the request and quickly identify any performance bottlenecks or failures across multiple services.
3846

3947
Here's the `Order microservice` implementation.
4048

@@ -150,25 +158,32 @@ public class ProductController {
150158
}
151159
```
152160

153-
## When to Use the Microservices Distributed Tracing Pattern in Java
161+
In this example, each microservice would typically be configured with tracing libraries (like Sleuth or OpenTelemetry). The trace context is propagated via HTTP headers, enabling the logs and metrics for each service call to be grouped together and visualized in Zipkin or another compatible tool. This ensures complete end-to-end visibility into each request’s journey.
154162

155-
* When you have a microservices architecture and need to monitor the flow of requests across multiple services.
156-
* When troubleshooting performance issues or errors in a distributed system.
157-
* When you need to gain insights into system bottlenecks and optimize overall performance.
163+
## When to Use the Microservices Distributed Tracing Pattern in Java
158164

165+
* When multiple services form a single user request path and debugging failures requires visibility across service boundaries.
166+
* When monitoring or diagnosing performance bottlenecks is critical in a multi-service environment.
167+
* When correlation of logs and metrics from independent services is needed to understand overall system health.
159168

160169
## Microservices Distributed Tracing Pattern Java Tutorials
161170

162171
* [Spring Boot - Tracing (Spring)](https://docs.spring.io/spring-boot/reference/actuator/tracing.html)
163172
* [Reactive Observability (Spring Academy)](https://spring.academy/guides/microservices-observability-reactive-spring-boot-3)
164173
* [Spring Cloud – Tracing Services with Zipkin (Baeldung)](https://dzone.com/articles/getting-started-with-spring-cloud-gateway)
165174

175+
## Real-World Applications of Microservices Distributed Tracing Pattern in Java
176+
177+
* OpenTelemetry for tracing instrumentation in Java services.
178+
* Spring Cloud Sleuth for automatic tracing in Spring Boot microservices.
179+
* Jaeger and Zipkin for collecting and visualizing distributed traces in Java-based systems.
180+
166181
## Benefits and Trade-offs of Microservices Distributed Tracing Pattern
167182

168183
Benefits:
169184

170-
* Provides end-to-end visibility into requests.
171-
* Helps in identifying performance bottlenecks.
185+
* Centralized insight into request paths across services, reducing time to diagnose issues.
186+
* Improved observability enables proactive identification of system bottlenecks.
172187
* Aids in debugging and troubleshooting complex systems.
173188

174189
Trade-offs:
@@ -177,20 +192,17 @@ Trade-offs:
177192
* Requires additional infrastructure (e.g., Zipkin, Jaeger) for collecting and visualizing traces.
178193
* Can become complex to manage in large-scale systems.
179194

180-
## Real-World Applications of Microservices Distributed Tracing Pattern in Java
181-
182-
* Monitoring and troubleshooting e-commerce platforms.
183-
* Performance monitoring in financial transaction systems.
184-
* Observability in large-scale SaaS applications.
185-
186195
## Related Java Design Patterns
187196

188-
* [Log Aggregation Microservice](https://java-design-patterns.com/patterns/microservices-log-aggregation/) - Distributed tracing works well in conjunction with log aggregation to provide comprehensive observability and troubleshooting capabilities.
189-
* [Circuit Breaker](https://java-design-patterns.com/patterns/circuit-breaker/) - Distributed tracing can be used alongside the Circuit Breaker pattern to monitor and handle failures gracefully, preventing cascading failures in microservices.
190-
* [API Gateway Microservice](https://java-design-patterns.com/patterns/microservices-api-gateway/) - The API Gateway pattern can be integrated with distributed tracing to provide a single entry point for tracing requests across multiple microservices.
197+
* [API Gateway Microservice](https://java-design-patterns.com/patterns/microservices-api-gateway/): Acts as an entry point to microservices and can propagate trace information to downstream services.
198+
* [Circuit Breaker](https://java-design-patterns.com/patterns/circuit-breaker/): Distributed tracing can be used alongside the Circuit Breaker pattern to monitor and handle failures gracefully, preventing cascading failures in microservices.
199+
* [Log Aggregation Microservice](https://java-design-patterns.com/patterns/microservices-log-aggregation/): Distributed tracing works well in conjunction with log aggregation to provide comprehensive observability and troubleshooting capabilities.
200+
* [Saga](https://java-design-patterns.com/patterns/saga/): Orchestrates distributed transactions, which benefit from trace identifiers to correlate steps across services.
191201

192202
## References and Credits
193203

194204
* [Building Microservices](https://amzn.to/3UACtrU)
195-
* [OpenTelemetry Documentation](https://opentelemetry.io/docs/)
196205
* [Distributed tracing (microservices.io)](https://microservices.io/patterns/observability/distributed-tracing.html)
206+
* [Microservices Patterns: With examples in Java](https://amzn.to/3UyWD5O)
207+
* [OpenTelemetry Documentation](https://opentelemetry.io/docs/)
208+
* [Release It! Design and Deploy Production-Ready Software](https://amzn.to/3Uul4kF)
Loading

Diff for: microservices-distributed-tracing/product-microservice/src/test/java/com/iluwatar/product/microservice/ProductControllerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ProductControllerTest {
3636
private ProductController productController;
3737

3838
@BeforeEach
39-
public void setUp() {
39+
void setUp() {
4040
productController = new ProductController();
4141
}
4242

0 commit comments

Comments
 (0)