If 2 people are obeying Allah and doing good deeds and if one dies at and early age and one after so many years, how there Amal will be calculated. I mean if the person who died early he may receive less rewards so how is the justice of Allah?

1- Allah looks at the quality of the deed. Sometimes a few years of good quality deeds are higher in value in the many years of lesser quality.

2- Allah takes our intentions into consideration when rewarding us. If the believer who died earlier had the intention to always obey Allah for as long as he lives, Allah will grant him that reward.

3- The one who died earlier might have less sins than the one who lives longer, so the greater number of sins committed by the longer living person can offset some of the more deeds he offered.