I would probably make an effort to avoid writing this code. It sounds like the kind of problem database replication was designed to solve. It would depend on criteria you don't communicate in your question, such as database engine in use, available transports, whether different locations updates would overlap each other, the design of the database as it relates to keys and unique indexes, etc.