How to run wp_insert_post() & wpdb on the background?

page load is not affected […] and the //METADATA is echoed/displayed immediately?

With your current setup, that is not possible. In order to display immediately, you need the data. To get the data, you need to wait.

Possible solutions are:

  1. Fetch the data before (e.g. via Cron) and populate the DB with the info. -> No need to fetch it live, but you might not know, which ids to get and which not to.

  2. Fetch the data asynchronous (e.g. via calling a REST endpoint in the template). -> Page will load fast, but parts are missing and rendered later. No need to pre-fetch the data though.