How to change core's default services Dependency Injection is added to core, but there's no documentation to tell how developer can alter the default services. For example, I would like to change cache.bootstrap class to APC Caching.
You can look at LanguageTestServiceProvider to see how alterations are made. Or I can offer my class:

&lt;?php
namespace Drupal\mongodb;

use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;

/**
 * MongoDB service provider. Registers Mongo-related services.
 */
class MongodbServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
  }

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    foreach ($container-&gt;findTaggedServiceIds('mongodb.override') as $id =&gt; $attribute) {
      $container-&gt;setDefinition(substr($id, 8), $container-&gt;getDefinition($id));
    }
  }

}


Basically, in alter you need to use the getDefinition method, do something with the definition and then use the setDefinition method to put it back.

and then here's the relevant parts of mongodb.services.yml:

services:
  mongodb.flood:
    class: Drupal\mongodb\Flood\MongoDBBackend
    arguments: ['@mongo', '@request']
    tags:
      - { name: mongodb.override }