Each word has a number of slightly different meanings. I am going to explain the difference between one meaning for "grade" and one for "rank."
A grade is a measurement on some scale. Because it is a measurement, they could fall anywhere. For example, on the first exam Alex gets a grade of 90, Blake a grade of 89, Casey a grade of 60. On the second, Alex gets 89, Blake gets 63, Alex gets 59.
To get the "rank," numbers are ranged in order and then assigned successive ranks. On the first exam, Alex ranks #1, Blake ranks #2, Casey ranks #3. On the second exam, despite getting different grades, Alex still ranks #1, Blake still ranks #2, and Casey still ranks #3.