Facebooks servers. Phones could not be capable of doing that much facial recognition that quick. Plus that bandwidth to grab all your friends images to compare to would be a metric ton of images given some selfie-addicts.