For denim knees specifically, the thing that made mine last: patch on the inside and sew from the outside in rows, rather than patching over the hole.
Fabric around a worn knee is already thin, so a patch stitched only at its edges tears out along the seam. Rows of stitching across the whole patch spread the load and it stops being a repair that fails next month.