Restore a backup to an patched version

If I take a backup of a cluster that is on v8.0.21 using xtraBackup, can I restore that backup to an instance running v8.0.40?

Yes — as long as both are within the MySQL 8.0 series, you can generally restore a physical backup taken with XtraBackup from MySQL 8.0.21 to a server running MySQL 8.0.40. XtraBackup is designed to be forward-compatible across minor releases within the same major version (8.0).

Thanks for the quick response!