In a saucepan, combine sugar and vinegar over medium heat.
Stir until the sugar dissolves completely.
Add ketchup and soy sauce to the mixture, stirring well.
In a separate bowl, mix cornstarch with water until smooth.
Gradually add the cornstarch mixture to the saucepan, stirring constantly.
Bring the sauce to a boil, continuing to stir.
Reduce heat and let it simmer for about 5 minutes.
Add minced garlic and ginger, stirring until fragrant.
Incorporate red pepper flakes for added heat, if desired.
Remove from heat and stir in sesame oil.