I don't know of any interesting mechanism that is specific to pain killers, so I will instead answer for drugs in general.

Drug action is a complex process consisting of many steps. Let's take a simple example: A systemic direct inhibitor of a kinase. This drug would need to*:


Be absorbed into your bloodstream
Remain in your bloodstream for sufficient time
Be absorbed into the tissue
Be able to bind the target protein


1 can fail due to interaction with other concurrently taken drugs or food, or simply genetic factors affecting the particular functioning of the gut mucosa. 2 can fail because the kidneys are too good at eliminating it, or the liver is metabolizing it too agressively (both also subject to modulation by other drugs, foods and genetic factors). 3 can fail because the transports in the cells aren't working as rapidly, or represent an allele less likely to take in the drug, or are modulated by other drugs/foods. The tissue can also have efflux pumps or enzymes that break down the drug. 4 can fail because the drug was designed for a specific allele of that kinase, but you happen to have a different allele, which has a slightly different structure that is no longer targeted by this drug.

Then you have a host of physiological variables, and addiction/tolerance.

Apparently the most common genetic reason by far for variable drug sensitivity is the specific set of CYP genes you have. CYP enzymes are abundant in the liver and chemically process various molecules (including drugs).

Besides this, an interesting set of specific examples used to be available from 23andme. I'm not sure if they still provide this after the FDA ban on health information.


Clopidogrel sensitivity - CYP2C19 variation
Proton Pump Inhibitor (stomach acid reduction) - CYP2C19 variation
Abacavir (HIV drug) - HLA-B*5701 SNP
Acetaldehyde (alcohol flush) - ALDH2 mutation
5-fluorouracil (chemotherapy) - DPYD mutation
PEG-IFN-alpha/RBV combination (Hepatitis C medicine) - IL28B SNP
Phenytoin (epilepsy drug) - CYP2C9 variants
Choline esters (class of muscle relaxants) - BCHE (CE degrader) variants
Sulfonylurea (used for type 2 diabetes) - CYP2C9 variants
Thiopurine (immune suppressant) -  TPMT (enzyme that degrades thiopurine) variation
Warfarin (anticoagulant) - CYP2C9 variants
Caffeine - CYP1A2 SNP
Metformin (diabetes drug) - SNP rs11212617, near the ATM gene
Antidepressant - SNPs in ABCB1 affect likelihood of sexual dysfunction (common side effect)
Beta-Blocker (heart disease) - Mutations in ADRB1 which is normally blocked by the drug
Floxacillin (drug for staphylococcal infections) - SNPs in the MHC region affect liver toxicity of this drug
Heroin - OPRM1 receptor (target of heroin) SNPs affect efficacy
Lumiracoxib (used to treat pain and symptoms of osteoarthritis) - SNPs in the MHC region affect liver toxicity
Naltrexone (alcohol and narcotic addiction drug) - SNPs in OPRM1 affect how much it can reduce pleasurable feeling from narcotics
Statins (cardiovascular disease) - SNPs in COQ2 (mitochondrial component) affect risk of myopathy


As you can see, our friends the CYP family enzymes come up frequently, and some are even repeat offenders like CYP2C9. Besides that, there is a fair number of cases where variation in the specific target of the drug are relevant.

Note that this list is not comprehensive: Many drugs have not been studied in sufficient detail, and some may have complicated mechanisms instead of just "bind and inhibit protein X".

I have omitted many details and links to literature, I am sure you can easily find them by searching on Google Scholar with the keywords I already gave. Let me know if that doesn't work, though.



*: Note that these aren't necessarily required for all drugs. For example, some drugs can be applied directly to the skin and hence do not need to pass through blood.

Why do different pain killers have different effects on people?
I would like to have the following output:


Text

(a) Text

Text
Text


That is, after a subitem, I want to return to the last number without creating a new one. Is there any way to do this without ERT?
