iluwatar / iluwatar/java-design-patterns

Timeout pattern

Open
#2,845 13 comments 0 reactions 1 assignee View on GitHub

@ylcn91 is already working on this.

Since Sep 7, 2026.

epic: pattern type: feature
Dominant language
Java
Stars
94.7k
Forks
27.4k
Avg merge
3d 4h
Merged PRs (30d)
10

Description

Description:
The Timeout design pattern is crucial in a microservices architecture to handle latency and prevent cascading failures. By setting a timeout, we can avoid long waits for responses from dependent services, improving overall system resilience and performance. This pattern helps in defining a period within which a service call must complete, otherwise, it gets aborted and a fallback mechanism is triggered. This implementation is particularly important for maintaining the robustness of the system under heavy load or when some services are down or slow to respond.

Main Elements of the Pattern:

  • Timeout Duration: Defines the maximum time a service call is allowed to take.
  • Fallback Mechanism: Provides a default response or alternative workflow if a service call times out.
  • Configuration: Ability to configure different timeouts for different services based on their response times.
  • Logging and Monitoring: Capture timeout events for monitoring and debugging purposes.
  • Circuit Breaker Integration: Work in conjunction with the Circuit Breaker pattern to prevent repeated calls to failing services.

References:

  1. Microservices Patterns
  2. Resilience4j - TimeLimiter
  3. Project Contribution Guidelines
  4. Timeout pattern

Acceptance Criteria:

  • Implement a configurable timeout for service calls.
  • Provide a fallback mechanism for timed-out calls.
  • Ensure the timeout duration can be configured per service.
  • Log timeout events for further analysis and monitoring.
  • Demonstrate the pattern with a practical example within the existing microservices.
  • Ensure the implementation follows the project's contribution guidelines and coding standards.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.