mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 20:14:59 +00:00
docs: update .editorconfig and reformat readmes
This commit is contained in:
1 parent
dfd34d890b
commit
de5a93c499
31 files changed
+387
-985
No files matched your search
+21
-54
@@ -19,27 +19,19 @@ Provide a helper service instance on a client and offload common functionality a
|
||||
|
||||
Real world example
|
||||
|
||||
> A remote service has many clients accessing a function it provides. The service is a legacy application and is
|
||||
> impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request
|
||||
> frequency should be implemented along with latency checks and client-side logging.
|
||||
> A remote service has many clients accessing a function it provides. The service is a legacy application and is impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request frequency should be implemented along with latency checks and client-side logging.
|
||||
|
||||
In plain words
|
||||
|
||||
> With the Ambassador pattern, we can implement less-frequent polling from clients along with latency checks and
|
||||
> logging.
|
||||
> With the Ambassador pattern, we can implement less-frequent polling from clients along with latency checks and logging.
|
||||
|
||||
Microsoft documentation states
|
||||
|
||||
> An ambassador service can be thought of as an out-of-process proxy which is co-located with the client. This pattern
|
||||
> can be useful for offloading common client connectivity tasks such as monitoring, logging, routing,
|
||||
> security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications,
|
||||
> or other applications that are difficult to modify, in order to extend their networking capabilities. It can also
|
||||
> enable a specialized team to implement those features.
|
||||
> An ambassador service can be thought of as an out-of-process proxy which is co-located with the client. This pattern can be useful for offloading common client connectivity tasks such as monitoring, logging, routing, security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities. It can also enable a specialized team to implement those features.
|
||||
|
||||
**Programmatic Example**
|
||||
|
||||
With the above introduction in mind we will imitate the functionality in this example. We have an interface implemented
|
||||
by the remote service as well as the ambassador service:
|
||||
With the above introduction in mind we will imitate the functionality in this example. We have an interface implemented by the remote service as well as the ambassador service:
|
||||
|
||||
```java
|
||||
interface RemoteServiceInterface {
|
||||
@@ -181,10 +173,8 @@ Time taken(ms):111
|
||||
|
||||
## Applicability
|
||||
|
||||
* Cloud Native and Microservices Architectures: Especially useful in distributed systems where it's crucial to monitor,
|
||||
log, and secure inter-service communication.
|
||||
* Legacy System Integration: Facilitates communication with newer services by handling necessary but non-core
|
||||
functionalities.
|
||||
* Cloud Native and Microservices Architectures: Especially useful in distributed systems where it's crucial to monitor, log, and secure inter-service communication.
|
||||
* Legacy System Integration: Facilitates communication with newer services by handling necessary but non-core functionalities.
|
||||
* Performance Enhancement: Can be used to cache results or compress data to improve communication efficiency.
|
||||
|
||||
Typical use cases include:
|
||||
@@ -199,57 +189,34 @@ Typical use cases include:
|
||||
|
||||
Benefits:
|
||||
|
||||
* Separation of Concerns: Offloads cross-cutting concerns from the service logic, leading to cleaner, more maintainable
|
||||
code.
|
||||
* Reusable Infrastructure Logic: The ambassador pattern allows the same logic (e.g., logging, monitoring) to be reused
|
||||
across multiple services.
|
||||
* Improved Security: Centralizes security features like SSL termination or authentication, reducing the risk of
|
||||
misconfiguration.
|
||||
* Separation of Concerns: Offloads cross-cutting concerns from the service logic, leading to cleaner, more maintainable code.
|
||||
* Reusable Infrastructure Logic: The ambassador pattern allows the same logic (e.g., logging, monitoring) to be reused across multiple services.
|
||||
* Improved Security: Centralizes security features like SSL termination or authentication, reducing the risk of misconfiguration.
|
||||
* Flexibility: Makes it easier to update or replace infrastructure concerns without modifying the service code.
|
||||
|
||||
Trade-offs:
|
||||
|
||||
* Increased Complexity: Adds another layer to the architecture, which can complicate the system design and debugging.
|
||||
* Potential Performance Overhead: The additional network hop can introduce latency and overhead, particularly if not
|
||||
optimized.
|
||||
* Potential Performance Overhead: The additional network hop can introduce latency and overhead, particularly if not optimized.
|
||||
* Deployment Overhead: Requires additional resources and management for deploying and scaling ambassador services.
|
||||
|
||||
## Known uses
|
||||
|
||||
* Service Mesh Implementations: In a service mesh architecture, like Istio or Linkerd, the Ambassador pattern is often
|
||||
employed as a sidecar proxy that handles inter-service communications. This includes tasks such as service discovery,
|
||||
routing, load balancing, telemetry (metrics and tracing), and security (authentication and authorization).
|
||||
* API Gateways: API gateways can use the Ambassador pattern to encapsulate common functionalities like rate limiting,
|
||||
caching, request shaping, and authentication. This allows backend services to focus on their core business logic
|
||||
without being burdened by these cross-cutting concerns.
|
||||
* Logging and Monitoring: An Ambassador can aggregate logs and metrics from various services and forward them to
|
||||
centralized monitoring tools like Prometheus or ELK Stack (Elasticsearch, Logstash, Kibana). This simplifies the
|
||||
logging and monitoring setup for each service and provides a unified view of the system's health.
|
||||
* Security: Security-related functionalities such as SSL/TLS termination, identity verification, and encryption can be
|
||||
managed by an Ambassador. This ensures consistent security practices across services and reduces the likelihood of
|
||||
security breaches due to misconfigurations.
|
||||
* Resilience: The Ambassador can implement resilience patterns like circuit breakers, retries, and timeouts. For
|
||||
instance, Netflix's Hystrix library can be used within an Ambassador to prevent cascading failures in a microservices
|
||||
ecosystem.
|
||||
* Database Proxy: Ambassadors can act as proxies for database connections, providing functionalities like connection
|
||||
pooling, read/write splitting for replicas, and query caching. This offloads significant complexity from the
|
||||
application services.
|
||||
* Legacy System Integration: In scenarios where modern microservices need to communicate with legacy systems, an
|
||||
Ambassador can serve as an intermediary that translates protocols, handles necessary transformations, and implements
|
||||
modern security practices, easing the integration process.
|
||||
* Network Optimization: For services deployed across different geographical locations or cloud regions, Ambassadors can
|
||||
optimize communication by compressing data, batching requests, or even implementing smart routing to reduce latency
|
||||
and costs.
|
||||
* Service Mesh Implementations: In a service mesh architecture, like Istio or Linkerd, the Ambassador pattern is often employed as a sidecar proxy that handles inter-service communications. This includes tasks such as service discovery, routing, load balancing, telemetry (metrics and tracing), and security (authentication and authorization).
|
||||
* API Gateways: API gateways can use the Ambassador pattern to encapsulate common functionalities like rate limiting, caching, request shaping, and authentication. This allows backend services to focus on their core business logic without being burdened by these cross-cutting concerns.
|
||||
* Logging and Monitoring: An Ambassador can aggregate logs and metrics from various services and forward them to centralized monitoring tools like Prometheus or ELK Stack (Elasticsearch, Logstash, Kibana). This simplifies the logging and monitoring setup for each service and provides a unified view of the system's health.
|
||||
* Security: Security-related functionalities such as SSL/TLS termination, identity verification, and encryption can be managed by an Ambassador. This ensures consistent security practices across services and reduces the likelihood of security breaches due to misconfigurations.
|
||||
* Resilience: The Ambassador can implement resilience patterns like circuit breakers, retries, and timeouts. For instance, Netflix's Hystrix library can be used within an Ambassador to prevent cascading failures in a microservices ecosystem.
|
||||
* Database Proxy: Ambassadors can act as proxies for database connections, providing functionalities like connection pooling, read/write splitting for replicas, and query caching. This offloads significant complexity from the application services.
|
||||
* Legacy System Integration: In scenarios where modern microservices need to communicate with legacy systems, an Ambassador can serve as an intermediary that translates protocols, handles necessary transformations, and implements modern security practices, easing the integration process.
|
||||
* Network Optimization: For services deployed across different geographical locations or cloud regions, Ambassadors can optimize communication by compressing data, batching requests, or even implementing smart routing to reduce latency and costs.
|
||||
* [Kubernetes-native API gateway for microservices](https://github.com/datawire/ambassador)
|
||||
|
||||
## Related patterns
|
||||
|
||||
* [Proxy](https://java-design-patterns.com/patterns/proxy/): Shares similarities with the proxy pattern, but the
|
||||
ambassador pattern specifically focuses on offloading ancillary functionalities.
|
||||
* Sidecar: A similar pattern used in the context of containerized applications, where a sidecar container provides
|
||||
additional functionality to the main application container.
|
||||
* [Decorator](https://java-design-patterns.com/patterns/decorator/): The decorator pattern is used to add functionality
|
||||
to an object dynamically, while the ambassador pattern is used to offload functionality to a separate object.
|
||||
* [Proxy](https://java-design-patterns.com/patterns/proxy/): Shares similarities with the proxy pattern, but the ambassador pattern specifically focuses on offloading ancillary functionalities.
|
||||
* Sidecar: A similar pattern used in the context of containerized applications, where a sidecar container provides additional functionality to the main application container.
|
||||
* [Decorator](https://java-design-patterns.com/patterns/decorator/): The decorator pattern is used to add functionality to an object dynamically, while the ambassador pattern is used to offload functionality to a separate object.
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
Reference in new issue
Block a user