Many populations in nature are fragmented: they consist of local populations occupying separate patches. A local population is prone to extinction due to the shot noise of birth and death processes. A migrating population from another patch can dramatically delay the extinction. What is the optimal migration rate that minimizes the extinction risk of the whole population? Here, we answer this question for a connected network of model habitat patches with different carrying capacities.