Lately I've encountered a similar problem in a few different circumstances, and every time it has required quite a bit of extra code to work around it.

The problem I'm talking about is the one where one application or device needs to send something to another application or device (usually a server). The thing being sent can be identified by a unique ID, but this ID is not known at the time of sending. It is instead generated or calculated by the receiver. Sort of a chicken-and-the-egg type of situation.

A common example is inserting a record into a database, and not knowing the ID of the newly inserted record until it has been inserted. My latest encounter was a situation where a mobile app needed to send an image and an accompanying textfile to a server, but the textfile couldn't be sent until the image had been received and an ID returned and inserted into the textfile. Pretty straightforward, until you start taking mobile network error handling into account...

This has cropped up in various forms lately, and I've noticed that usually it requires a lot more complexity to let the receiver generate an ID than would be required if I could just let the sender generate a UUID/GUID/whatever and send it along with whatever I'm sending.

So I'm curious - does this problem have a common name? And am I right in thinking that the best/least complex approach usually is to let the sender set the ID instead of the receiver?



That would be the problem's common name.

What you need to do is flip the problem on its head. How do I know how to refer to your dog before you have introduced your dog's name to me, by the way I've decided to nickname the dog wuffles. (Hint one way is italicised, the other is in bold.)

It boils down to either a mechanical description, kind of like an address, or to name it myself and introduce it to you.

On the receiving side no one says you have to use the same name, or that you cannot augment the name mechanically/randomly. Following the dog example on receipt translate the your dog/wuffles to the dogs actual name, or Kain's your dog, or User 12345's wuffles.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.