Before talking about addiction prevention, I would like to provide a concise and comprehensive explanation of addiction. Your perception, both of your emotions and of your body, is shaped by the balance of chemicals in your brain. When you use a substance which quickly changes your perception, you are altering this chemical balance. Physical addiction is when your body and brain become used to these altered chemical levels. You can become physically addicted to any substance that has the potential to cause physical dependence - even if you never used it to feel high.
Dopamine is one of the chemicals in your brain which helps motivate you to engage in healthy behaviors such as eating, socializing, and exercising. You take care of yourself, and your brain gets a bit of dopamine to encourage you to continue keeping yourself alive and well. If a person uses a dopamine-releasing drug every day, their brain will recognize that there is much more dopamine than usual, and produce less of it in an attempt to return to its normal chemical balance. But this means if they stop using this drug, their brain is no longer producing as much dopamine as it was before they started using regularly. Though it will return to that previously normal balance after a period of time (exactly how long varies by substance), the re-adjustment period is what we know as withdrawals, and it is an incredibly uncomfortable, painful, and - for some substances - dangerous process.
Psychological addiction is just as serious as physical addiction, and the two often come hand in hand. Even substances which are not physically addictive can be psychologically addictive. Psychological addiction is when a person has used a substance in order to cope for an amount of time which has lead them to lose any other coping strategies that may have previously had for dealing with stress. This could look like a person using a certain substance every time they are feeling sad. When it comes to psychological addiction, one might not even be the same substance every time, but they feel the need to use something every time they are struggling.
If you want to use recreationally without developing a dependence, there are a fair number of precautions you need to take.
1) Know the addiction potential of your drugs, and space out your use accordingly
In general, it is safe to use the same drug once every one or two weeks. This is true in terms of physical addiction and protection from bodily harm. The notable exceptions to this are MDMA and MDA, both of which are likely to cause brain damage - including but not limited to serotonin syndrome - if used more than one every 30-40 days. It is also generally inadvisable to use psychedelics this frequently, both because it often takes around two weeks for the experience to fully settle, and because of the risk of brain damage from research chemicals, or drug-induced psychosis. Make sure you feel as though you have full perspective on the impact your experience had on you before using again. Using different forms of any opioid, stimulant, or benzodiazapine, is essentially the same as using the same substance. So taking hydrocodone on Monday, and morphine on Thursday, is not adhering to the 1-2 week rule.
Of course, the 1-2 week rule can be broken while still maintaining perfect physical and emotional health - but don't forget that making exceptions to the rule should be an outlier. The moment it stops being abnormal to regularly use one substance more often than that, is when you should start to worry.
2) Keep yourself in a healthy routine
Eat 2-3 good meals every day, keep your space and body clean, exercise, sleep, and socialize. If you have work or school, prioritize punctuality and deadlines. If at any point you find your use of any drug impairing your ability to do any one of these things more than once every 1-2 weeks, it's time to cut back on your use.
3) Watch for psychological changes
Being physically well is a very helpful thing for maintaining your mental health, but there is always more you can do. Anyone who uses any substance (especially stimulants or psychedelics) on a semi-regular basis, should make sure that they consistently evaluate their mental state. Residual effects are not something that should be ignored, even if they aren't bothersome.
4) Stay away from people engaging in behaviors you do not want to take part in
Even if you feel like you have above average self-control, being around addicts is the easiest way to make yourself into one. Your environment shapes you more than you think. The other side of this, is to intentionally have people in your life who value harm reduction and safety as much as you do.