We have daily 200-300 live projects which receive online traffic from our vendors across all our live projects. We store this data in two different DB (I know this sounds bad, but seemed good at the time of designing for various reason):
- project information in -
projectstable ofMySQL - traffic data for those projects in
MongoDB collection.
Now, we have to generate analytical data out of these data that we store like on a given date-range - Revenue Earned, Profit, Top Vendors, Top Projects(with most conversion), etc... This data has to be stored daily somewhere so that we can query it by Date Range.
The only problem is that one project traffic is divided between multiple vendors. So this kind of makes it nested data because for a project we can have 10 vendors records.
What's the best way to store this kind of data so that I can query it easily for my representation purpose?
UPDATE
The Project Table contains details about project like -
Project_Code | Client Code | Sales Manager |Payout | Status | Country Code ...
The Traffics collection contains detail about the traffic on a particular project Like -
UUID | Project_Code | Vendor Code | Start Time | End Time | Conversion Status |...
When we have to pull project-wise stats we fetch all the projects and then sum up the traffic for corresponding project_code so that we can get
Project Code | Total Starts(sum of traffic for that project code) | Conversion (Sum of Traffic with conversion_status=1) | Incidence Length (Avg of Median(Endtime - Start time))
So this is what we have so far in our DB
Now what we want is to daily mine this data so that we can calculate
(Given Date Range - Like Last 7 Days, Today, This Month)
First View. Project Code | Revenue Earned (Conversion * Payout) | Cost to Company (sum(Vendor Conversion * Vendor Cost)) | Profit (Revenue - Cost)
Second View. First view but where Sales Manager = "John"
Third View. Top n vendors | Top n Projects | ...
Fourth View. Same as the Third View but where Sales Manager = "John"
So far we are using Laravel, Mysql, MongoDB, Redis as tech stack.