Search code examples
phpmongodbdatabase-designrestful-architectureapi-design

Optimization of data - MongoDB and PHP for a RESTful API


This is more about an architectural decision for which I'm currently neither an expert in data storage or retrieval, specifically for MongoDB.

I currently have a RESTful API built in PHP-Slim framework, and have external devices submitting POST requests every second. For scalability, imagine if I had 100 devices, so 100 requests per second to process.

Each device submits 3 separate voltages - volt_a, volt_b, volt_c along with a device_id and time stamp, which gets stored as a single document. Now every time I run an aggregation pipeline, I need to $project the average voltage for every document, every time.

My question is, as I'm performing large aggregation queries over a large number of documents (for example, 1 hours data so 3600 documents) would it be better to just to calculate and store the average voltage in my POST method in PHP, as opposed to having to keep projecting it which impacts the aggregation performance?


Solution

  • The original question was posed more theoretical in nature, however it seems that in order to gain further insight I'll have to implement both methods and measure the performance of both to get a satisfactory answer.