The modules are loaded in the order they are mentioned in config.php as interpreted by the following quote from devdocs;
You can check your module’s load order from the <magento_root>/app/etc/config.php file after you’ve successfully set up Magento. This file is created dynamically at run time during set up.
Reference : https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/module-load-order.html
I also did some digging myself and found that if you mention the sequence in a module.xml the the dependent module is loaded before the current module.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_ComponentB" setup_version="0.0.1">
<!-- Vendor_ComponentB is dependent on Vendor_ComponentA: -->
<module name="Vendor_ComponentA" />
According to above module.xml module A will be listed before module B in config.php and hence, loaded before the module B. Note that they may not be listed in the neighbouring nodes but the general order will be as expected always.