Search code examples
c#xamarinarchitecture.net-6.0

Handling external requests from Backend and sharing to mobile app


I've an Android app made on Xamarin .net 2.1 standard and a backend (REST API using .net6 and MySQL). From an architecture perspective, I don't know what is the best option so I ask for your help.

At this moment, from mobile app every time a user refreshes Dasboard Page, backend do rest call over https to an external endpoint to retrieve json, then do some calculations data and send back to mobile so user can see data updated (it's binance api call to obtain btc ptice in usdt and eur).

As this is a very bad idea when goes into production, I'm thinking how to solve it. My main idea, is creating console app that proactively does that call every 5 seconds and save it somewhere (may saving to file can cause lots disk access hahaha). At the end that data collected must be shared in some efficient way so mobile can fetch that data... What you think could be the best approach? I know that I can stream that values from Binance using Websockets but can't see clear what's best choice and how to connect to mobile. Thanks all!


Solution

  • First of all if you are working on a financial project you should know that each second is important , so the idea of getting data every 5 seconds is not a good idea, so let's go to explain a better way :
    As you said and is obvious the best way in this situation is to get your data from webSocket because it's real-time and it's so reliable and you are always update.
    But there is a problem and that's there are lots of data sending to you, so you should be able to handle it. to handle this volume of data, the best offer is to use JAVA and it's frameworks like Spring.
    So this was one part of problem now let's go to the second part.
    what should you do with these data ?? where should you persist them ??
    As you maybe noticed before, your data is a time-based data.
    When it comes to time-based data , the best choice is : Postgres timescale DB.
    Install a Postgres and create a database then apply timescale DB plugin on your database.
    Now every thing is ready, create a time-based table in your timescale db .
    Now persist price of each seconds on it.
    each time your front-end refreshed the page just select from your table ((time based select is highly optimized in Postgres timescale DB, even in large amount of records )) and return the last price to it. Beside that you have the price of each moment.
    Even you can stream the data to your front-side too.
    Feel free to ask any question you need to know.