Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Design approach/advice on implementing a currency exchange rate service

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to develop a service that checks constantly the currency exchange rate between Euro and Dollar. I have started thinking about its basic implementation and I am going to do the following:

- Create a Spring Boot application including:
  • Exchange Entity;
  • Exchange Repository;
  • Exchange Controller with one endpoint getting the latest exchange rate as well as historical rates by using optional parameters such as startDate to endDate;
  • Exchange Service


  • I have a question regarding the current plan. Amongst my requirements the service needs to check constantly the rate and to me this suggests that I need implementing publisher/subscriber architecture. I was thinking to use https://spring.io/projects/spring-data-redis and implement a listener.bWhat is your view? I welcome any advice to improve upon my current planned implementation.


    Thank you,

     
    Saloon Keeper
    Posts: 7172
    166
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Just to make sure: the WS returns the exchange rate, and you want that WS to update its data in the background, independently from any client invocation?

    What do you mean by "check the rate" - retrieving it from some other remote service?

    Given that this is a single data point, I think using Redis would be overkill.

    And I don't really see a pub/sub design, given that you're building a WS.
     
    Geane Norm
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim Moores wrote:Just to make sure: the WS returns the exchange rate, and you want that WS to update its data in the background, independently from any client invocation?

    What do you mean by "check the rate" - retrieving it from some other remote service?

    Given that this is a single data point, I think using Redis would be overkill.

    And I don't really see a pub/sub design, given that you're building a WS.



    Hi,
    thank you for your reply. I would simply like the WS to return the exchange rate, nothing more. Are you suggesting that I do not really need to have a repository implementation? Regarding the "check the rate" question, that is a good one. Is there any existing currency converter I could be using for the actual conversion?

    OK, I was mislead by the fact that the WS needs to return the rate value "continuously" and that to me suggested that there should be a listener of some sort.

    Thank you
     
    Tim Moores
    Saloon Keeper
    Posts: 7172
    166
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There are freely available currency conversion WS out there. Either make your WS a proxy for one of them, or retrieve the rates you need to support in regular intervals (might once a day be sufficient? If not, maybe once per hour) and perform the conversion in your WS. I would advise the latter, as the former adds a network round-trip on top of the round-trip to your WS - not a good solution. (It would also raise the question: why use your WS if the client could simply use the other one instead?)
     
    Saloon Keeper
    Posts: 24541
    168
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The xe.com currency exchange website provides an API you can invoke. It's not free, but ir you really need minute-by-minute exchange rates, then presumably you're doing something lucrative enough to pay the fee that allows you to keep polling their servers that often.
     
    Geane Norm
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim Moores wrote:There are freely available currency conversion WS out there. Either make your WS a proxy for one of them, or retrieve the rates you need to support in regular intervals (might once a day be sufficient? If not, maybe once per hour) and perform the conversion in your WS. I would advise the latter, as the former adds a network round-trip on top of the round-trip to your WS - not a good solution. (It would also raise the question: why use your WS if the client could simply use the other one instead?)



    Thank you once again. Do you have any particular suggestion for the currency conversion service? I have found a few of them here: https://stackoverflow.com/questions/3139879/how-do-i-get-currency-exchange-rates-via-an-api-such-as-google-finance, but it is a new territory for me. From an implementation point of view, shall I then remove the repository itself that is of no use and create a response call that would call directly whatever api I will eventually choose? Is this what you meant by just retrieving the rates at regular intervals? I would not want to implement an additional layer when I can simply query a reliable service and use the response for my own WS. Or is there any other good approach for using an external api from within your own Spring app?

    Thank you,

    Regards
     
    Tim Moores
    Saloon Keeper
    Posts: 7172
    166
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No, I can't recommend one, as I've never had to use one.

    I'm not sure what you mean by "repository". What you should not do is to query some other WS every time you receive a request. Instead, cache the result for some time (maybe for an hour, if daily isn't good enough), and then update it in the background.

    What point would there be in handling each request by turning around and calling some other WS every single time?
     
    Marshal
    Posts: 26912
    82
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim Moores wrote:What point would there be in handling each request by turning around and calling some other WS every single time?



    If your front-end was better and cheaper than the front-end which is supplied by the web service's owner, that could be a reason. Or if your front-end was doing a lot of client service work which is not supplied by the web service's owner and can absorb the cost of the web service. But it sounds like that's not the case.

    I have XE's Android app on my devices and it works just fine and it's free (a.k.a. infested by ads). By the way it refreshes its conversion rates every 60 seconds, so you might find that a suitable interval too.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic