Skip to content

Feat/idr rate aggregator ahmad#160

Open
ahmad-shiddiqi wants to merge 10 commits intoallobankdev:mainfrom
ahmad-shiddiqi:feat/idr-rate-aggregator
Open

Feat/idr rate aggregator ahmad#160
ahmad-shiddiqi wants to merge 10 commits intoallobankdev:mainfrom
ahmad-shiddiqi:feat/idr-rate-aggregator

Conversation

@ahmad-shiddiqi
Copy link
Copy Markdown

Architectural Rationale

Polymorphism Justification (Strategy Pattern)

The application exposes a single multi-resource endpoint that serves different financial data types. Instead of implementing conditional logic (e.g., if-else or switch) inside the service layer, the Strategy Pattern is used.

Each resource type implements a common IDRDataFetcher interface. This design:

  • Adheres to the Open/Closed Principle
  • Allows new resource types to be added without modifying existing logic
  • Keeps the service layer clean and focused
  • Improves maintainability and testability

This approach scales better than a conditional block, which would grow increasingly complex as new resource types are introduced.


Client Factory (FactoryBean)

A FactoryBean is used to construct the external API client.

The FactoryBean:

  • Encapsulates client construction logic
  • Centralizes WebClient configuration
  • Allows future enhancements such as interceptors, timeouts, retries, or authentication
  • Decouples client configuration from business components

While a simple @Bean method could create the client, the FactoryBean approach provides greater flexibility and better separation of concerns for external integrations.


Startup Runner Choice (ApplicationRunner)

ApplicationRunner is used for initial data ingestion instead of @PostConstruct.

This is preferred because:

  • It runs after the full Spring context is initialized
  • It clearly separates lifecycle execution from bean initialization
  • It provides better control over startup sequencing
  • It aligns better with production-grade startup handling

Using @PostConstruct would mix initialization logic with bean lifecycle concerns and provides less explicit control over execution timing.


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.

1 participant