Skip to content

Add Microservices Bulkhead pattern implementation (#3228)#3326

Open
beingadish wants to merge 8 commits into
iluwatar:masterfrom
beingadish:feature/microservices-bulkhead
Open

Add Microservices Bulkhead pattern implementation (#3228)#3326
beingadish wants to merge 8 commits into
iluwatar:masterfrom
beingadish:feature/microservices-bulkhead

Conversation

@beingadish

Copy link
Copy Markdown

What does this PR do?

  • Implements resource isolation with dedicated thread pools
  • Demonstrates fail-fast behavior under load

Fixes #3228

- Implements resource isolation with dedicated thread pools
- Demonstrates fail-fast behavior under load
- Fixes iluwatar#3228
@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown

PR Summary

Implemented resource isolation with dedicated thread pools (UserService, BackgroundService) via a base BulkheadService and added a complete Microservices Bulkhead module. Demonstrates fail-fast behavior when queues are full and preserves isolation between critical user requests and background processing. Added Task model and TaskType enum, demo App, unit tests, and root pom update. Fixes #3228

Changes

File Summary
microservices-bulkhead/README.md Introduces Bulkhead pattern concepts and usage with a Java example module, documenting intent and practical scenarios.
microservices-bulkhead/pom.xml Adds a standalone Maven module with dependencies (JUnit, Mockito, AssertJ) and build plugins; marks module as part of root reactor.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java Implements demo orchestrating UserService and BackgroundService with scenarios and reporting, showcasing resource isolation and fail-fast behavior.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java Defines BackgroundService with a dedicated thread pool and queue to isolate non-critical tasks from user requests.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java Core abstract service with a bounded thread pool, fail-fast rejection, and task processing logic; exposes metrics getters and shutdown.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java Represents a Task with name, type, and durationMs; Lombok @Getter provides accessors; includes toString.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java Defines TaskType enum with USER_REQUEST and BACKGROUND_PROCESSING.
microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java Critical UserService with its own bulkhead pool and queue; overrides rejection handling to propagate behavior.
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/AppTest.java Tests that App.main runs without throwing exceptions.
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BackgroundServiceTest.java Verifies background task acceptance, overflow behavior, and isolation from user service overload.
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BulkheadServiceTest.java Tests capacity, rejection, and basic metrics (getActiveThreads, getQueueSize).
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTest.java Tests getters and toString formatting for Task.
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTypeTest.java Tests enum values for TaskType.
microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/UserServiceTest.java Tests user request acceptance and isolation from overloaded background service.
pom.xml Root POM updated to include the new microservices-bulkhead module in the reactor.

autogenerated by presubmit.ai

@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2025

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Dec 3, 2025

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity.

@github-actions github-actions Bot added the Stale label Dec 3, 2025

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (2)
  • da16647: Merge branch 'master' into feature/microservices-bulkhead

  • 0dc5355: Add Microservices Bulkhead pattern implementation

  • Implements resource isolation with dedicated thread pools

  • Demonstrates fail-fast behavior under load

  • Fixes #3228

Files Processed (8)
  • microservices-bulkhead/README.md (1 hunk)
  • microservices-bulkhead/pom.xml (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java (1 hunk)
Actionable Comments (0)
Skipped Comments (5)
  • microservices-bulkhead/pom.xml [2-9]

    best_practice: "License header cleanliness in module pom"

  • microservices-bulkhead/pom.xml [68-73]

    maintainability: "Unneeded Lombok dependency in module"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java [85-97]

    enhancement: "Blocking sleep in worker thread"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java [31-37]

    enhancement: "Background rejection handling lacks specific logic"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java [32-37]

    enhancement: "User service rejection handling lacks user-facing fallback"

@beingadish

Copy link
Copy Markdown
Author

Hi @iluwatar , kindly merge this PR

@github-actions github-actions Bot removed the Stale label Jun 6, 2026

@iluwatar iluwatar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new module to parent pom.xml, otherwise it's not built by CI at all.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • 068950a: Merge branch 'iluwatar:master' into feature/microservices-bulkhead
Files Processed (0)
Actionable Comments (0)
Skipped Comments (0)

* Remove `org.projectlombok:lombok` dependency.
* Add explicit version `3.27.7` to the `org.assertj:assertj-core` test dependency.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (5)
  • 59d1228: build: update dependencies in microservices-bulkhead
  • Remove org.projectlombok:lombok dependency.
  • Add explicit version 3.27.7 to the org.assertj:assertj-core test dependency.
  • d812403: build: add microservices-bulkhead module to root pom

  • 068950a: Merge branch 'iluwatar:master' into feature/microservices-bulkhead

  • da16647: Merge branch 'master' into feature/microservices-bulkhead

  • 0dc5355: Add Microservices Bulkhead pattern implementation

  • Implements resource isolation with dedicated thread pools

  • Demonstrates fail-fast behavior under load

  • Fixes #3228

Files Processed (9)
  • microservices-bulkhead/README.md (1 hunk)
  • microservices-bulkhead/pom.xml (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (3)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java [67-78]

    enhancement: "Clarify and extend the rejection path for observability"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java [31-37]

    enhancement: "Background rejection hook could implement fallback"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java [31-37]

    enhancement: "User rejection handling could expose a user-facing fallback"

Refactor all core classes and add comprehensive test coverage for the
Microservices Bulkhead pattern.

Refactored:
- BulkheadService: overhaul thread pool isolation logic
- App: update demo to reflect revised service APIs
- BackgroundService, UserService: align with updated BulkheadService
- Task, TaskType: revise model structure and toString representation
- pom.xml: update module dependency configuration

Added tests:
- AppTest: verifies main entry point runs without exception
- BulkheadServiceTest: task acceptance, overflow rejection, active thread
  count, queue size reporting, and graceful shutdown
- BackgroundServiceTest: task submission, bulkhead overflow, and isolation
  from UserService overload
- UserServiceTest: user request acceptance and isolation from overloaded
  BackgroundService
- TaskTest: name, type, duration getters and toString format
- TaskTypeTest: enum values USER_REQUEST and BACKGROUND_PROCESSING
- Task: used Lombok @Getter

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (2)
  • c1951c4: Refactored:
  • Task: used Lombok @Getter
  • 73fe983: feat(microservices-bulkhead): refactor implementation and add unit tests

Refactor all core classes and add comprehensive test coverage for the
Microservices Bulkhead pattern.

Refactored:

  • BulkheadService: overhaul thread pool isolation logic
  • App: update demo to reflect revised service APIs
  • BackgroundService, UserService: align with updated BulkheadService
  • Task, TaskType: revise model structure and toString representation
  • pom.xml: update module dependency configuration

Added tests:

  • AppTest: verifies main entry point runs without exception
  • BulkheadServiceTest: task acceptance, overflow rejection, active thread
    count, queue size reporting, and graceful shutdown
  • BackgroundServiceTest: task submission, bulkhead overflow, and isolation
    from UserService overload
  • UserServiceTest: user request acceptance and isolation from overloaded
    BackgroundService
  • TaskTest: name, type, duration getters and toString format
  • TaskTypeTest: enum values USER_REQUEST and BACKGROUND_PROCESSING
Files Processed (14)
  • microservices-bulkhead/pom.xml (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/AppTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BackgroundServiceTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BulkheadServiceTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTypeTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/UserServiceTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (2)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java [14-16]

    best_practice: "Missing Lombok dependency for Task model"

  • microservices-bulkhead/pom.xml [68-74]

    test: "JUnit 5 API dependency missing"

Skipped Comments (0)

Comment thread microservices-bulkhead/pom.xml

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • 9d51b47: style: add license headers and apply Google Java Format
Files Processed (12)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java (1 hunk)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/UserService.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/AppTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BackgroundServiceTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BulkheadServiceTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTypeTest.java (1 hunk)
  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/UserServiceTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (12)
  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/Task.java [1-45]

    maintainability: "Lombok usage for Task"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BulkheadService.java [1-159]

    maintainability: "BulkheadService rationale and capabilities"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/BackgroundService.java [1-57]

    maintainability: "BackgroundService rationale and delegation"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/App.java [1-138]

    maintainability: "App entry point demonstrating the Microservices Bulkhead"

  • microservices-bulkhead/src/main/java/com/iluwatar/bulkhead/TaskType.java [1-36]

    maintainability: "TaskType enum structure"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/AppTest.java [1-32]

    maintainability: "AppTest invokes App.main"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BulkheadServiceTest.java [1-80]

    maintainability: "BulkheadService basic tests"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BackgroundServiceTest.java [1-73]

    maintainability: "BackgroundServiceTest overview"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/AppTest.java [1-32]

    maintainability: "AppTest invokes App.main"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTest.java [1-54]

    maintainability: "Task unit tests"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/TaskTypeTest.java [1-44]

    maintainability: "TaskType enum tests"

  • microservices-bulkhead/src/test/java/com/iluwatar/bulkhead/BulkheadServiceTest.java [1-80]

    maintainability: "BulkheadService basic tests"

@iluwatar

iluwatar commented Jun 7, 2026

Copy link
Copy Markdown
Owner

@beingadish consider rebasing on top of master. There were spotless issues that were fixed just moment ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Microservices Bulkhead pattern

2 participants