Many countries face the problem of how to reform social security systems to cope with increasing life expectancy. This raises questions concerning both distribution and risk sharing across generations. These issues are addressed within an OLG model with stochastic life expectancy across generations and endogenous retirement decisions. The social optimum is shown to imply that retirement age should be proportional to longevity. Moreover, increasing longevity calls for pre-funding even if the utility of all generations is weighted equal to the objective discount rate. The social optimum cannot be decentralized due to a conflict between incentives and risk sharing. The implications of stylized social security systems for risk sharing and retirement incentives are analyzed.