The primary objectives of this study were to analyse the nationwide healthcare trajectories of heart failure (HF) patients in France, 2years after their first hospitalization, and to measure sequence similarities. Secondary objectives were to identify the association between trajectories and the risk of mortality. A retrospective, observational study was conducted using data extracted from the Echantillon Généraliste des Bénéficiaires database, covering the period from 1 January 2008 to 31 December 2018. Follow-up concluded upon death or at the end of the study. We developed a methodology specific to healthcare data by extracting frequent healthcare trajectories and measuring their similarity for use in a survival machine learning analysis. In total, 11488 HF patients were included and followed up for an average of 2.9±1.3years. The mean age of the patients was 78.0±13.2years. The first-year mortality rate was 31.7% and increased to 78.8% at 5years. Fifty per cent of patients experienced re-hospitalization for reasons related to cardiovascular diseases. We identified 1707 hospitalization sequences, and 21 sequences were associated with survival, while 15 sequences were linked to mortality. In all our models, age and gender emerged as the most significant predictors of mortality (permutation feature importance: 0.099±0.00078 and 0.0087±0.00018, respectively; weights could be interpreted in relative terms). Specifically, the age at initial hospitalization for HF was positively associated with mortality. Gender (male: 49.5%) was associated with poorer prognoses. Healthcare trajectories, including non-surgical device treatments, valve replacements, and atrial fibrillation ablation, were associated with a better prognosis (permutation feature importance: 0.0047±0.00011, 0.0014±0.000073, and 0.00095±0.000097, respectively), except in cases where these invasive treatments preceded or followed hospitalization for cardiac decompensation. The predominant negative prognosis sequences were mostly those that included HF-related hospitalizations before or after other-related hospitalizations (permutation feature importance: 0.0007±0.000091 and 0.00011±0.000045, respectively). We highlight the value of healthcare trajectories on frequent hospitalization sequences, mortality, and prognosis and indicate the necessary prognostic value of HF re-hospitalization. Our work may be an essential tool for better identification of at-risk patients in order to increase and improve personalized care in the future.