MOSFET as switch with 2 voltage sources
can there be different voltage sources like in my schwematic with common ground?
  


Absolutely. Only the voltage difference between the source and the gate counts for turning on the transistor; anything else can be a free-for-all as long as the circuit makes sense.


  
  As I understand, R2 only restricts the current flowing from GPIO to GROUND
  


Incorrect. R2 allows the gate to drain once there is no voltage applied to the gate, since the gate of a MOSFET acts as a capacitance. Without R2 the transistor would take many, many orders of magnitude longer to turn off since only the leakage current could drain the gate capacitance, assuming a switch as shown in the schematic. Actual GPIO outputs are usually push-pull, and hence both source and sink current, so R2 wouldn't be required at all were one being used.

How large R2 should be depends on both the current available from the supply connected to the gate as well as the desired turn-on and turn-off times; the larger R2 is, the weaker the supply can be, the faster the turn-on time will be, and the slower the turn-off time will be.