Yes, yet another question regarding this subject... But even if there is some information on salesforce forums, I think some of that is outdated (since the Portals became Communities and there were some changes in the few last releases). Maybe someone experienced with Communities in their present state (May 2015) could provide an answer that would be valid for Summer'15 release?
But let's go to the point, let me explain the details:
Our organization has the "ACME" Community created. We need to create "ACME" Community users from Apex (this functionality is exposed to the guest users by RemoteAction calls from custom VisualForce page that has some functionality "injected" by the usage of Javascript framework that makes XHR calls to VF through VisualForce Remoting). That is the technical background.
Now, the external app needs to create a Community user. It uses the email form for the username (eg. "[email protected]"). Under the hood, we are appending the suffix consisting of constant string denoting our community name and InstanceName (eg. EU1) from Organization object. The real SFDC Community username then becomes eg. "[email protected]".
I think that it is enough for providing the uniqueness on production. But what if we have 5 sandboxes, and all of them will land on the same instance, eg. CS15? Will our application be able to create the Community user with name [email protected] on each of the sandboxes?
And what if the other company that uses salesforce will create their community also named "ACME" and this will also land on the EU1 instance? If John Doe would also like to create user with the same name "[email protected]" (let's say this time typed in manually)? Will there be a username conflict (duplicated usernames)?