Aggregated Data Table (Reporting Table) in CloudKit database

I need to track user actions, for example video view count. Then the data is used to get most popular videos for last 7 days, 30 days and for a year. For this purpose I have created a Downloads table with timestamp and video fields.

Each time user opens the catalog, I'm running queries to get Downloads and sort the videos based on them. This is a working, but not the efficient solution. A good option is to add aggregated data table storing summary counts for the popular queries - countFor7Days, etc. This will improve query performance. But it requires a job that would update the aggregate table every day.

The question is how to implement this job in CloudKit? Is there are such built-in feature, or I need a custom service running somewhere?

Replies

I wish CloudKit had jobs, too, but alas…

One idea is to have clients do the job. Check if there's a recent aggregate record, and if not, create one. Sure, you might have several clients doing similar work at similar times, but you won't have the cost of running a server somewhere.

@deeje, ha-ha, yeah. I also thought about it. Some unlucky clients will do all the chore :D

:-) As a developer, one of the things I love about CloudKit is that the cost is paid for entirely by the customers themselves. If we extend that thinking from storage to storage+compute, and we recognize that we have to build a distributed job system anyway, well it just makes sense to use the compute resources that the customer already has.