Skip to content

Forex Assignment Submission#83

Open
Hydrino wants to merge 14 commits intopaidy:masterfrom
Hydrino:forex-submission-ninad
Open

Forex Assignment Submission#83
Hydrino wants to merge 14 commits intopaidy:masterfrom
Hydrino:forex-submission-ninad

Conversation

@Hydrino
Copy link

@Hydrino Hydrino commented Mar 4, 2026

Live Forex Rate Proxy Implementation

This PR implements the Forex rate proxy service as part of the Paidy interview assignment. More details added in README.

Key changes:

  • OneFrameLive --> fetches from OneFrame upstream, caches results in-memory
  • Input validation --> missing/unsupported currency params return 400 before hitting upstream
  • Error mapping --> One-Frame always returns HTTP 200; errors are decoded from the body and mapped to 400 / 500 / 502 accordingly
  • Same-currency pairs (USD→USD) return price: 1.0 without an upstream call
  • Structured logging via log4cats — cache hits/misses, upstream latency, all error branches
  • Unit tests --> 21 tests covering Currency, OneFrameLive (stub client), and HTTP routes

Design decisions, assumptions, and known trade-offs are documented in the README.

Hydrino added 14 commits March 2, 2026 20:33
Setting up integration with the OneFrame service.
Changes made:
1. Added blaze client dependency to be able to make http calls upstream
2. Added one-frame service application configurations
3. Modified existing service port to avoid clashing with one-frame service port
Adding a live interpreter to make actual upstream service calls. Returns dummy response for now.

Changes made:
1. Adding a new def live in Interpreters.scala
2. Modified Module.scala to get the live service instead of dummy
3. Created a new OneFrameLive.scala to return a dummy response.
Replace dummy response with actual call to the OneFrame API. Error handling, caching will be implemented in the next commits.
Update Currency .fromString safe in order to catch query params user errors.
Adding input validations to our proxy service. Added validations to ensure "to" and "from" are present in input request, if not, return 400 response to the client.
Added validations to ensure correct "to" and "from" currency codes from the user. If invalid, returns back 400 response. Changes include:

1. Making Currency fromString complete by adding default case
2. Using `OptionalValidatingQueryParamDecoderMatcher` instead of `OptionalQueryParamDecoderMatcher`
3. Updated RatesHttpRoutes.scala to handle input error cases, along with the case of from==to
Added error response handling from the rate service. Proxy service converts it to appropriate program level errors, and RatesHttpRoutes.scala converts it to correct http responses.
Caching rates locally from the upstream one-frame service. We leverage the fact that we can receive multiple currency pair conversion rates in a single call to the upstream service. Key considerations:

1. TTL is set to 4 mins (requirement is <5 min). Max request to upstream (60/4)*24 = 360/day, which is well within <1000/day requirement

2. If cache becomes stale or does not exist, we call the upstream with all the currency pairs possible(72) and cache them all at once locally. This greatly reduces the number of calls to the upstream (by 72x)
Added logs in key operations. Using the `log4cats-slf4j` library.
Utilizing timeouts and +1 retry on the upstream OneFrame Service. Adding these on the blaze client itself rather than at call-level since there is only 1 upstream.
1. Changed `fetchFromOneFrameAndCache` to `fetchFromOneFrame` to keep single responsible
2. Added documentation where essential
3. Minor refactors
Added Scala unit tests for the following:
1. Currency
2. OneFrameLive
3. RatesHttpRoutes
Added log statement specifying the latency in ms for each .get call to the OneFrameLive service.
@Hydrino Hydrino marked this pull request as ready for review March 4, 2026 05:42
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