For ESP32 - recommend paying close attention to the FreeRtos, it's seriously powerful. Even if you are just using Arduino style code you can use it for background scheduling and interrupts (for your api and buttons for example), as well as dual core use on S3.