Question: "Base on your experience, please provide a solution to scale the application if the number of users growing very quickly."
I made a mistake of premature optimization during this development test as I spent more time than I should thinking about this question. My thoughts about catching up rapidly users growth:
Make it easier for developers to make contributions, faster iteration loop is the key. Thus I spent too much time polished the development framework and don't have enough time to accomplish all the task required.
Add more tests to ensure we won't break anything between each releases.
To improve the flexibility and maintainability of our codebase, we can aim for abstraction and decoupling of components, allowing for easier addition of new features. For instance, in this project, I utilized ethersproject to decouple the login process from relying solely on Metamask, making it possible to easily add support for other wallets in the future.
The services combined in this project can be split into its own server, like data stream server, database server, web server, account server, notification server and event distribute server, etc. Making it easier to find the bottleneck of the system, and implement horizontal scaling by adding more servers as needed. We can use a load balancer to distribute traffic across multiple servers, which can help handle increased traffic and improve reliability.
Cache the data we need, avoid making expansive rpc calls if possible.
To optimize performance, we can proactively prepare the data our users need, such as performing necessary RPC calls ahead of time and caching the data upfront, so that it is readily available when the user requests it from our server.
Adapting asynchronous processing patterns more to offload time-consuming tasks to improve performance and provide more user-friendly experiences.
Notes
I got "project ID does not have access to archive state" error when firing BalanceAt call to Infura with given blockNumber, so I used Infura in this project to query the latest balance only.
I was planned to maintain a subscription to the the Infura event source at the start of the server and designed the whole architecture of the web service accordingly. But when I implemented it near the end of this week after i finished the account page and balance page, I just found the ws connect silently failed. Possibly due to the proxy running on my computer did not play well with websocket connection from inside docker. Which is wired because the go get command from inside the docker did run well and the websocket connection between my go backend and vue front is working without any problem. I spent a lot of time tried to solve this issue but unfortunately without any success. I panicked as this indicated the attempts I tried to implements this server is flawed and the idea of subscribing to the event source and prefetch block & transaction data in the background for the Index Page is not achievable via Infua, and therefore I did not have enough time to finish the whole project before the deadline. I'll try to implement this feature by communicating with other api provider.
I used moralis's deep-index api to find native transactions in order to seed the db when a new address is checked.
I used morails's api to call BalanceAt with blockNumber to get historic balance data.
Websocket now broadcast all data updates, this is only for demonstration. And the result is not filtered, so frontend will update even if the updates is unwanted, this should be fixed.
Questions
Question: "Base on your experience, please provide a solution to scale the application if the number of users growing very quickly."
I made a mistake of premature optimization during this development test as I spent more time than I should thinking about this question. My thoughts about catching up rapidly users growth:
ethersproject
to decouple the login process from relying solely on Metamask, making it possible to easily add support for other wallets in the future.Notes
BalanceAt
call toInfura
with given blockNumber, so I usedInfura
in this project to query the latest balance only.Infura
event source at the start of the server and designed the whole architecture of the web service accordingly. But when I implemented it near the end of this week after i finished theaccount page
andbalance page
, I just found the ws connect silently failed. Possibly due to the proxy running on my computer did not play well with websocket connection from inside docker. Which is wired because thego get
command from inside the docker did run well and the websocket connection between my go backend and vue front is working without any problem. I spent a lot of time tried to solve this issue but unfortunately without any success. I panicked as this indicated the attempts I tried to implements this server is flawed and the idea of subscribing to the event source and prefetch block & transaction data in the background for theIndex Page
is not achievable viaInfua
, and therefore I did not have enough time to finish the whole project before the deadline. I'll try to implement this feature by communicating with other api provider.moralis
's deep-index api to find native transactions in order to seed the db when a new address is checked.morails
's api to callBalanceAt
with blockNumber to get historic balance data.TODOs