Longevity is the determining factor! And there's nothing immigration law can do about that. However, current immigration law allows people to bring in their parents - often elderly relatives. Since there is no bar to bringing in elderly relatives, this actually exacerbates the "problem" of the "elderly population." Bringing in lots of older people who will never work long enough & earn enough to qualify for Social Security & Medicare. This is a major contributor to the problem!
Another factor in the Social Security/Medicare going-bust equation is the huge numbers of people who are collecting Social Security/Medicare who never paid into the system! E.g. lots of parents claiming "disabled" kids, who will never pay in a cent, and burn up all parents' contribs long before parents retire. Lots of illegal aliens claiming disability, too. Identity theft, id fraud, misuse of SSN by illegal aliens are also factors bankrupting Social Security. It's not the people who work 30, 40, 50 years before retirement who cause any problems with Social Security. It's older immigrants, illegal aliens, and people who collect without ever contributing to their own account who cause all the trouble.