Most scalable approach to adding new data to a database?

I have a Rails website with three tables: User, Task, and TaskInstance. The Task table is like a master list of tasks, not coupled to any particular user, whereas the TaskInstance table contains records that indicate a user's completion of a particular task. In other words, a TaskInstance has a User id, a Task id, and a completion status (boolean). A User has many TaskInstances.

I'd like to allow administrators to add new Tasks. Doing so should create a new TaskInstance for that Task for every User. However, that doesn't sound like it would scale well. Say I have fifty thousand Users, creation of a new Task would require fifty thousand TaskInstances to be created immediately on the spot.

It would be good if some sort of lazy loading could be done instead, but I don't know where I would do it. I could do it at login e.g. when a User logs in, check if a new Task has been created; if so, create a new TaskInstance only for that particular User. But then what about users that are already logged in when the new Task is created?

I guess I'm just wondering what the preferred approach to this sort of problem is.

Move this to the community wiki if you need to.

Upvotes: 0

Views: 71

Answers (1)

klaffenboeck
klaffenboeck

Reputation: 6377

Don't create the TaskInstances right upfront, but only when they are needed. Since a new Task gets created anyway, it can be displayed to any User, no matter if there is a TaskInstance or not. As soon as a user decides to start with a Task, the TaskInstance should get instantiated.

Upvotes: 2

Related Questions