In my application I have the concept of an Order which it is a resource that is a collection of other resources (Draws). (background: How to RESTfully support the creation of a resource which is a collection of other resources and avoiding HTTP timeouts due to DB creation?)
When a user creates an Order in the API, it will submit a JSON that looks like this:
{
"order": {
"draws": [
{
"background_color" : "rgb(0,0,0)", "font_size" : 14
},
{
"background_color" : "rgb(255,0,0)", "font_size" : 16
},
...
]
}
}
Then, my application will return a tracking number to the User so he can see what is the current status for that Order, and will push that JSON to a queue so that it can be processed in the background.
However, I have a problem:
Once the Order is completed, and the User fetches the Order, I will return a list of Draws. Something like this:
"draws": [
{
"background_color" : "rgb(0,0,0)", "font_size" : 14, "url" : "generated_url"
},
{
"background_color" : "rgb(255,0,0)", "font_size" : 16, "url" : "generated_url2"
},
...
]
My problem is:
How will the User know which Draw from the results is a draw from what he submited? Here is two solutions I have thought of:
1 - When the user submits the Order, for each of the Draws he submits a unique id, so later when those are created, he will be able to map them.
2 - When the user submits the Order, my application creates a unique id for each of the Draws. And later when the Draws are actually created in the DB, I put that unique id into the DB.
What is more reasonable, taking into account that an Order can have up to 100.000 draws.