If not already deemed obsolete (and aren't all of them before about 2017 now?), 2015 and before are "vintaged" which means the "few years use" you seek will be on MBs without security updates, etc... unless you apply hacks to make them run newer versions of macOS than Apple approves (which seems to be a security risk in itself).
My suggestion is to embrace M-series if you want a hack-free Mac to last "a few years" unless this is a money-driven thing and that’s impossible. If so, the best option may be to jump to PC where competitive forces in abundance can deliver a lot of 2024 PC power for what you’d probably spend for an 8-year-old used Mac.
I’m about an Apple everything guy myself, but PC is not nearly as bad as fans make it out to be. And all that competition for all parts like RAM & SSDs will deliver a LOT of value for the same money. A 2024 PC is going to have fresh everything for “next few years” and beyond. And it can run a whole lot more apps than even the best Mac can run.
An often-overlooked problem with the old Mac approach- and I have 2 older Macs myself- goes beyond security updates. Apple apps tend to inevitably update with each new macOS update and the file format is tweaked to no longer open on older versions (than maybe 2 generations at best). So for example, someone sends you a Pages/Numbers/Keynote file that they've tweaked on a newer Mac and you can't open it on the 2015. Or you make some edits to a such a file, send it to someone else to have a look and further tweak, they send your own file back to you... but now you can't open it. And of course, core apps like Safari will no longer update... and websites you want to access will stop working (changing browsers can remedy this issue but then you are trusting Google or similar as browser app).
Bottom line: when vintaged... or, in your case, even within the 3 years window of vintaging (which likely incorporates the very last of the Intel Macs now), that ship has sailed. While I still have 2 older Macs in use, they are locked to their final official macOS update and they continue to be used for special purposes that can still work on them. Mainstream stuff like Safari browsing and using the unique Apple apps is done on a much newer M-series Mac to "keep up" with Apple's way to pressing people to buy new.
That shared though: since I needed full Windows (not ARM Windows) for some business needs anyway, embracing Silicon meant embracing "old fashioned bootcamp" too... so, for the first time in about 20 years, I bought a new PC. PC competition means that about half its cost isn't only profit margin. PC RAM & SSD costs a fraction of Apple RAM & SSD. I decided to go bigger than "cheapest" so I basically budgeted what Apple charges for the 8TB SSD upgrade and purchased a full gaming PC with graphics card, 10TB of SSD and 32GB or RAM.
By the time I need to buy my next laptop, if Apple hasn't addressed the exploitive pricing of RAM & SSD, I'll probably replace my MBpro with a Windows laptop. The bulk of what one wants to get done on a computer gets done just about as well on either platform. And I'd rather my purchase cash buys more computer than rains maximum wealth onto shareholders.
I think Mac and macOS is great and all- I use it every single day- but, for me anyway, the abundant focus on delighting shareholders at the expense of customers is getting towards that "enough is enough" moment. A few decades ago, I had one Apple computer and a bunch of tech by "others." 10+ years ago, it became about Apple everything and little tech by others. Now ridiculous pricing is encouraging a full circle choice again.
You- OP- are likely best served to put your Apple purchase budget towards a robust, 2024 PC vs. a vintaged 2015 Mac. You'll certainly get a lot more computer for the same money if you do so. But if it must be Mac, find a way to get at least an M1, which should still have the "a few years" you seek in them before they are vintaged (probably starting in 2026-27 or so).