ctci/09. System design and scala.../9.7. Personal financial man...

3.2 KiB

9.7. Personal financial manager

Design a personal financial manager, which connects to your bank accounts, analyze your spending habits, and make recommendations

Assumptions:

  • This program is an extension of the browser and runs in the background, every time you open your bank account, the service is activated and the data updated in real time. same with mobile.
  • Otherwise, it would be a program that the user opens when they want to find data, then the app connects to the bank, processes the new data, and shows metrics or gives recommendations.

We can choose option 2.

The user will have to give the bank details somehow, through an API, or some other secure connection. The program will have a hidden variable of a timestamp, showing when the app was opened last. On the first run, the program will fetch all the bank information until date, and will save the current timestamp. The next time the program is open, the program will fetch the data from the saved timestamp until current, to avoid fetching all data at all times. The program can also have a 'Refresh' button to fetch new data if the user wants it, in which case the timestamp will be updated.

Ideally, the fetched data will come in some readable format, json, xml. The service will parse this format, and save the information in memory. Given that this program is for one user only, not many transactions are expected per day. We can make an assumption of no more than 20 transactions per day. For security reasons, this data can stay in the user's pc or mobile in an encrypted format.

There can be a list of all the user's accounts, and at each fetch new transactions are appended to this. NLP tools or regex methods could make it possible to categorize each purchase into a different category, also with earnings from the salary etc. We can have a visualize function to see a graph of money fluctuation through time, overall and per category.

We can use traditional ML models as decisions trees or random forests for predictive analysis of future expenses. The user can add a monthly budget per account or category, and the system can update them if the expenses are nearing this limit.

Hints

Try to reduce unnecessary db queries. If you don't need to permanently store the data in the db, you might not need it in the db at all.

So what, I can fetch all data every time the user wants to? That is a lot of data each time.

As much work as possible should be done asynchronously

Solution

The user should be able to update the category if it is improperly assigned. In that case, the AI would adapt to it. Notifications could be done per email, either regularly or when some limit is reached, not necessarily when the user opens the program.

Another assumption might be that the updates don't have to be instantaneous, a delay of 24h could be acceptable. We can pull the data periodically. Asynchronously, we could queue up tasks, each one with a specific priority. Lowest priority tasks would eventually also get done, just later. But they wouldn't be in the queue forever because there are new higher priority tasks, eventually lower priority tasks are also done.

The solution also includes some tips to categorize transactions.