I think good quality pellets specifically designed for goldfish are better than flakes, flakes tend to go stale a lot quicker than pellets (which leads to a reduction in nutritional content and molds can also start to grow). Most cases of goldfish having constipation from overfeeding of dried foods often involves pellets. Pellets also tend to be a less messy food in general for goldfish than flakes- as the goldifish grows larger, you can also get larger pellets brands more suited for the goldfishes size and type.
A good goldfish diet though shouldn't entirely consist of dried foods, you should try and feed frozen foods like bloodworms or fresh veg like cooked and chopped up peas or spinache too.