Long before Snape becomes a professor at Hogwarts, he attends the school as one of its pupils. And while attending Hogwarts, he finds an enemy in James Potter (Adrian Rawlins), Harry Potter's eventual father. Since Snape is in Slytherin House and James is in Gryffindor House and Hogwarts thrives on ideological segregation, the two were never going to be fast friends, but Snape and James hate each other ... a lot. Snape's hatred is, in part, fueled by jealousy. James is an accomplished Quidditch player and is well-liked by most people for being a charming rapscallion.
Their feud stretches all the way back to their first journey on the Hogwarts Express, where Snape (Benedict Clarke) and James (Alfie McIlwain) argue over the merits of their preferred Hogwarts Houses and those who belong in them. It's an argument that Snape triggers but one that James enthusiastically escalates. In later spats, James does not wait for Snape to put his foot in his mouth and instead chooses to humiliate him in front of a cheering crowd. Yes, Snape is a pure-blood supremacist with a sulky demeanor, but James is a vicious, attention-seeking bully. There are no winners here.
Fast-forward to when young Harry arrives at Hogwarts. Snape is a grown man, 31 years old, and he runs into this child who looks exactly like his old rival. Both the books and the films go to great pains to hammer home just how similar Harry looks to his father, so it's not just a passing resemblance. In Harry, Snape sees someone who treated him like filth. Does it justify Snape's similar behavior toward Harry? No, obviously not.