Microkernel with low bootstrap level?
A lot of the bootstrap process happens now implicitly as services are requested.

If nothing requests the database service then Drupal won't open the connection to it and so on.

The minimal amount of code to do a custom php file that bootstraps Drupal and does some queries can be seen in statistics.php:

$autoloader = require_once 'autoload.php';

$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod');
$kernel-&gt;boot();
$container = $kernel-&gt;getContainer();

$views = $container
  -&gt;get('config.factory')
  -&gt;get('statistics.settings')
  -&gt;get('count_content_views');

if ($views) {
  $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
  if ($nid) {
    $container-&gt;get('request_stack')-&gt;push(Request::createFromGlobals());
    $container-&gt;get('statistics.storage.node')-&gt;recordView($nid);
  }
}


Depending on what it is for, you could also do a normal controller and return a cacheable JsonResponse with the right cache tags and contexts, then Drupal will automatically cache that in the internal and dynamic page cache. Which, depending on your queries, might not be much or not at all slower.