At least since the work of Kjetil Storesletten, we know that it is possible to find an immigration policy that can make social security sustainable. But is such a policy politically feasible, taking xenophobia aside?
Edith Sand and Assaf Razin address this question with a very simple overlapping-generations model. Obviously, old people prefer having lots of (young) immigrants as well as high tax rates that will both sustain their pensions (we are talking about a pay-as-you-go plan). Young people clearly prefer low tax rates on their income, but it is unclear what they prefer in terms of immigration policy. They like high immigration quotas because it implies that there will be more when they are old, as immigrants have higher fertility rates. But they also like lower rates for the following reason: immigrants once old have the right to vote, as their descendants. Due to their fertility, this may shift the median voter from the old to the young and thus reduce future pensions. To top all this, immigrants depress wages (what the young do like) but increase the return of capital (what the old like).
All this implies that there can be immigration policy cycles. If the country is primarily populated by old people, it will let in a lot of immigrants. But once the young are in majority, borders are closed, until the old get sufficiently numerous. Guess where we are headed.