How gojek/heimdall works
Main Components
• Core HTTP Client: Represent the base HTTP client (e.g., client.go in the root and in the httpclient package) that exposes a fluent interface for making requests.
• Retry & Backoff Mechanism: Include elements for “Backoff” (backoff.go and its test files) and “Retry” (retry.go and its test files) which handle the logic for retrying failed requests with configurable strategies (e.g., constant, exponential, or custom backoff).
• Plugin System: Highlight the extensibility provided by the plugin interface (plugin.go and plugins directory). This includes hooks (OnRequestStart, OnRequestEnd, and OnError) that allow additional behaviors such as logging (e.g., the request_logger plugin).
• Custom HTTP Client Integration: Indicate that Heimdall allows custom HTTP client implementations by accepting a Doer (interface similar to net/http.Client) and wrapping them with added functionality (as described in the README).
Architectural Patterns and Design Principles
• Façade pattern: Heimdall provides a simple interface (fluent methods like client.Get() and client.Do()) while hiding the complexity of retries, circuit breaking, etc.
• Layering/Separation of Concerns: Separate components like retry logic, circuit breaker logic, and plugin management are modular. This modularity should be shown by drawing distinct layers and clearly marking inter-component communication.
• Extensibility: Show how plugins attach to the core client to extend functionality without modifying the base logic.
Technologies and Frameworks
• Go (Golang) as the primary language.
• References to standard HTTP functionalities (net/http) that are being wrapped by Heimdall.
What
• Start at “Client Construction” where options such as timeouts, retry counts, and custom functionalities are set.
• Branch off from this core process into “Retry Logic” and “Circuit Breaker” components if errors occur.
• Clearly differentiate between the base HTTP functionality and the additional safety/resiliency layers.
Final Assembly
• Conclude the flow with the outgoing request to the external HTTP endpoint.
• Annotations to highlight the use cases mentioned in the README, such as handling high volume requests, supporting retries, and implementing circuit breaking.