Python Dictionary vs Database (e.g. an SQL Database)

Viewed 29

I am trying to make a programme that receives multiple data from many different shopping APIs around the web regarding some product prices in different supermarkets.

I want to store these data to my programme and then access them and manipulate them by finding each products lowest price in the different supermarkets. The data are constantly changing so storing, getting and manipulating them should happen as fast as possible.

Until now i am storing them in a dictionary but i was wondering if an SQL database (or another database) could make the programme run faster.

For example i have received and stored the following data in a dictionary(but the number of supermarkets are over 100 and the products are also over 1000 in each one).Would storing and getting them for manipulation from a database would be faster than a dictionary?

pricesDict = { "supermarket_1": {"apples": 1, "bananas": 2, "melons": 3},
               "supermarket_2": {"apples": 1.5, "bananas": 2, "melons": 3},
               "supermarket_3": {"apples": 1, "bananas": 2, "melons": 3},
               "supermarket_4": {"apples": 1, "bananas": 2.7, "melons": 3}}

Thanks!

1 Answers

It will probably not run faster. In memory operations are very fast compared to writing out to any sort of disk storage. Are you writing your dictionary to disk? If you're reading and writing your entire dataset for persistence then you could see some performance improvements.

However, it will add reliability and robustness to your application as well as the ability to add referential integrity constraints to your data model if necessary. I don't see how you're managing locking and conflicting updates, so it may simplify that. It will also make your data durable (survives restart).

Related