It depend on case by case.
both words meaning in english is prevention.
but 예방 have more meaning. That is preparing about something in future.
So if you know something when appear, then using 예방.
but you don't know something when appear, but know it is possilbe appear, then using 방지.
ex) 예방주사 : already know, when will be flu come.
과속 방지턱: We don't know when car has overspeed, but that make car can't has overspeed.