You have to find the right swim classes. We started our children in swim classes at 2 years old, but I was never very satisfied with the instruction they were receiving. I could see them struggling with things and the instructors would just sort of give them nudges in the water to get them to go in the direction they wanted, but weren't really working on explaining things. They also made the kids sit on the side of the pool when it wasn't their turn, so 2/3rds of the 30 minutes they were there, they weren't in the water, getting comfortable with it, learning not to fear it.
When our youngest turned 3, they moved him up to a class where I no longer got in the pool with him, and he was not ready for that. I told them he wasn't ready and they didn't listen. Ultimately, he wasn't getting enough time in the water to get over his fear of getting his face wet, and the instructors were rushing him too much that he started hating going. So we took him out and I bought a 12' diameter, 20" deep pool for the back yard (oof, getting the ground leveled to set it up was quite an ordeal). He is still aprehensive when he first gets in, but usually after about 30 minutes he's asking me to put on goggles so he can stick his face in the water. He'll get there.
Our oldest is 5. His first swim classes were at a different place entirely, but we moved out of there and had to find a new place (the place I hate). So I think he got a better foundation of familiarity with the water to then be able to get something out of the classes at the later school. He swims like a fish now. He recently attended a pool party for a friend's birthday and swam non-stop for pretty much 2 hours.
The "large kiddie pool" or "small above ground pool" was a good balance of cost (I probably put $300 total into the pool, setting it up, and care equipment/chemicals) and capacity for what they need, which is really just "figuring out how their bodies work in water."
The school that I hate is called Goldfish. They're a national chain. Avoid them, if at all possible.