Overview & Challenge
Every company works with a lot of data. The data increases over time and the system which handles it becomes slow and sometimes even not functional. One of our European clients in the finance industry is working with a lot of data from other companies. For the purpose of our client’s working, they should have basics information about the companies they collaborate with. And since they have become one of the ten fast-growing companies, the data load increased a lot over time. The challenge that they have encountered was populating 35 tables in a brand new database with data from a response that was coming from an external API.
The old structure wasn’t applicable, because if they were to respond to the challenge, 100+ more files would have to be created. That was not an option, because the system was already too big, adding those files meant just making it more difficult to handle all those requests. Moreover, using the old system meant difficulties in the maintenance, and performance of the code.
The solution that we proposed was changing the approach and redoing the code completely. The project that we were working on was a Laravel project and to get data from the database we used the following layers – Controller – Service – Repository.
- We created migrations for all the tables.
- We created a model for all the tables. It was necessary because we use the Eloquent ORM and we plan to use it in the future.
- Then followed the main PHP class and mappings JSON file. Due to the multiple levels of indentations, we created relationships between the tables with proper keys. All relationship methods were added and defined in that main parent object/Model.
The JSON structure was extended for some tables with one additional keyword: relationship.
There is a third level of indentation too. In that case, we defined the relationships in the main parent model, but there is another property added in the response, so we can easily define all relationships and insert the records.
• Maintainable and reusable code.
• Performance advantages – fast execution/insertion of data in all tables. 50% faster insertion of data in the tables.
• Easier adding of new mappings that work with the existing code.
• Increased functionality with fewer files and fewer lines of code.