diff --git a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
index 2bf41e0f4c..93c8b57df1 100644
--- a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
@@ -25,6 +25,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
     'block_content',
     'comment',
     'forum',
+    'history',
     'node',
     'statistics',
     // BlockManager->getModuleName() calls system_get_info().
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
index db255d79f8..4b4d25152b 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
@@ -20,6 +20,7 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal6TestBase {
     'block',
     'comment',
     'forum',
+    'history',
     'views',
     'block_content',
     'content_translation',
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
index 6ea998b0c9..c0ffc804bb 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
@@ -26,6 +26,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
     'aggregator',
     'book',
     'forum',
+    'history',
     'statistics',
   ];
 
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
index 3201d02b16..dacb779517 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
@@ -23,6 +23,7 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal7TestBase {
     'comment',
     'filter',
     'forum',
+    'history',
     'views',
     'block_content',
     'config_translation',
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 051f335c80..b919bddeed 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -64,7 +64,7 @@
  * Comments changed after this time may be marked new, updated, or read,
  * depending on their state for the current user. Defaults to 30 days ago.
  *
- * @todo Remove when https://www.drupal.org/node/1029708 lands.
+ * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
  */
 define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60);
 
diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php
index 86dfeacadb..ac5678ae50 100644
--- a/core/modules/comment/src/CommentLinkBuilder.php
+++ b/core/modules/comment/src/CommentLinkBuilder.php
@@ -205,7 +205,8 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
           $entity_links['comment__' . $field_name]['#attached']['library'][] = 'comment/drupal.node-new-comments-link';
           // Embed the metadata for the "X new comments" link (if any) on this
           // entity.
-          $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id());
+          $timestamps = \Drupal::service('history.repository')->getLastViewed($entity->getEntityTypeId(), [$entity->id()], $this->currentUser);
+          $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) $timestamps[$entity->id()];
           $new_comments = $this->commentManager->getCountNewComments($entity);
           if ($new_comments > 0) {
             $page_number = $this->entityTypeManager
diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php
index f7458f4d57..598d34663f 100644
--- a/core/modules/comment/src/CommentManager.php
+++ b/core/modules/comment/src/CommentManager.php
@@ -217,20 +217,8 @@ public function getCountNewComments(EntityInterface $entity, $field_name = NULL,
     if ($this->currentUser->isAuthenticated() && $this->moduleHandler->moduleExists('history')) {
       // Retrieve the timestamp at which the current user last viewed this entity.
       if (!$timestamp) {
-        if ($entity->getEntityTypeId() == 'node') {
-          $timestamp = history_read($entity->id());
-        }
-        else {
-          $function = $entity->getEntityTypeId() . '_last_viewed';
-          if (function_exists($function)) {
-            $timestamp = $function($entity->id());
-          }
-          else {
-            // Default to 30 days ago.
-            // @todo Remove once https://www.drupal.org/node/1029708 lands.
-            $timestamp = COMMENT_NEW_LIMIT;
-          }
-        }
+        $timestamp = \Drupal::service('history.repository')->getLastViewed($entity->getEntityTypeId(), [$entity->id()], $this->currentUser);
+        $timestamp = $timestamp[$entity->id()];
       }
       $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT);
 
diff --git a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
index b1a3de16f4..b24ae748ff 100644
--- a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
+++ b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
@@ -164,7 +164,7 @@ public function preRender(&$values) {
 
     if ($nids) {
       $result = $this->database->query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment_field_data} c ON n.nid = c.entity_id AND c.entity_type = 'node' AND c.default_langcode = 1
-        LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN ( :nids[] )
+        LEFT JOIN {history} h ON h.entity_id = n.nid AND h.uid = :h_uid WHERE n.nid IN ( :nids[] )
         AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp1), :timestamp2) AND c.status = :status GROUP BY n.nid", [
         ':status' => CommentInterface::PUBLISHED,
         ':h_uid' => $user->id(),
diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
index f6263fee1a..3836ddf2b8 100644
--- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
+++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
@@ -9,6 +9,7 @@
 use Drupal\node\NodeInterface;
 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
 use Drupal\Tests\UnitTestCase;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
 
 /**
  * @coversDefaultClass \Drupal\comment\CommentLinkBuilder
@@ -87,6 +88,16 @@ protected function setUp() {
     $this->stringTranslation->expects($this->any())
       ->method('formatPlural')
       ->willReturnArgument(1);
+
+    $history_repository = $this->getMockBuilder('Drupal\history\HistoryRepositoryInterface')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $history_repository->expects($this->any())
+      ->method('getLastViewed')
+      ->willReturn(0);
+    $container = new ContainerBuilder();
+    $container->set('history.repository', $history_repository);
+    \Drupal::setContainer($container);
   }
 
   /**
@@ -321,13 +332,3 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com
   }
 
 }
-
-namespace Drupal\comment;
-
-if (!function_exists('history_read')) {
-
-  function history_read() {
-    return 0;
-  }
-
-}
diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml
index 6268c2cf8a..a83af7fea2 100644
--- a/core/modules/forum/forum.services.yml
+++ b/core/modules/forum/forum.services.yml
@@ -1,7 +1,7 @@
 services:
   forum_manager:
     class: Drupal\forum\ForumManager
-    arguments: ['@config.factory', '@entity_type.manager', '@database', '@string_translation', '@comment.manager', '@entity_field.manager']
+    arguments: ['@config.factory', '@entity_type.manager', '@database', '@string_translation', '@comment.manager', '@entity_field.manager', '@history.repository']
     tags:
       - { name: backend_overridable }
   forum.breadcrumb.node:
diff --git a/core/modules/forum/src/ForumManager.php b/core/modules/forum/src/ForumManager.php
index 29e03e1cb7..33ca731cc6 100644
--- a/core/modules/forum/src/ForumManager.php
+++ b/core/modules/forum/src/ForumManager.php
@@ -13,6 +13,7 @@
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\comment\CommentManagerInterface;
 use Drupal\node\NodeInterface;
+use Drupal\history\HistoryRepositoryInterface;
 
 /**
  * Provides forum manager service.
@@ -120,6 +121,13 @@ class ForumManager implements ForumManagerInterface {
    */
   protected $index;
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
   /**
    * Constructs the forum manager service.
    *
@@ -135,8 +143,10 @@ class ForumManager implements ForumManagerInterface {
    *   The comment manager service.
    * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
    *   The entity field manager.
+   * @param \Drupal\history\HistoryRepositoryInterface $history_repository
+   *   The history repository service.
    */
-  public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager = NULL) {
+  public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager = NULL, HistoryRepositoryInterface $history_repository = NULL) {
     $this->configFactory = $config_factory;
     $this->entityTypeManager = $entity_type_manager;
     $this->connection = $connection;
@@ -147,6 +157,11 @@ public function __construct(ConfigFactoryInterface $config_factory, EntityTypeMa
       $entity_field_manager = \Drupal::service('entity_field.manager');
     }
     $this->entityFieldManager = $entity_field_manager;
+    if (!$history_repository) {
+      @trigger_error('The history.repository service must be passed to ForumManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2081585.', E_USER_DEPRECATED);
+      $history_repository = \Drupal::service('history.repository');
+    }
+    $this->historyRepository = $history_repository;
   }
 
   /**
@@ -329,16 +344,11 @@ protected function getTopicOrder($sortby) {
    *   previously viewed the node; otherwise HISTORY_READ_LIMIT.
    */
   protected function lastVisit($nid, AccountInterface $account) {
+    $this->history += $this->historyRepository->getLastViewed('node', [$nid], $account);
     if (empty($this->history[$nid])) {
-      $result = $this->connection->select('history', 'h')
-        ->fields('h', ['nid', 'timestamp'])
-        ->condition('uid', $account->id())
-        ->execute();
-      foreach ($result as $t) {
-        $this->history[$t->nid] = $t->timestamp > HISTORY_READ_LIMIT ? $t->timestamp : HISTORY_READ_LIMIT;
-      }
+      $this->history[$nid] = HISTORY_READ_LIMIT;
     }
-    return isset($this->history[$nid]) ? $this->history[$nid] : HISTORY_READ_LIMIT;
+    return $this->history[$nid];
   }
 
   /**
@@ -498,7 +508,7 @@ public function checkNodeType(NodeInterface $node) {
   public function unreadTopics($term, $uid) {
     $query = $this->connection->select('node_field_data', 'n');
     $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', [':tid' => $term]);
-    $query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', [':uid' => $uid]);
+    $query->leftJoin('history', 'h', "n.nid = h.entity_id AND h.entity_type = 'node' AND h.uid = :uid", [':uid' => $uid]);
     $query->addExpression('COUNT(n.nid)', 'count');
     return $query
       ->condition('status', 1)
@@ -506,7 +516,7 @@ public function unreadTopics($term, $uid) {
       //   field language and just fall back to the default language.
       ->condition('n.default_langcode', 1)
       ->condition('n.created', HISTORY_READ_LIMIT, '>')
-      ->isNull('h.nid')
+      ->isNull('h.entity_id')
       ->addTag('node_access')
       ->execute()
       ->fetchField();
diff --git a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
index 9b9661b5a2..01664be733 100644
--- a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
+++ b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
@@ -18,7 +18,7 @@ class ForumValidationTest extends EntityKernelTestBase {
    *
    * @var array
    */
-  public static $modules = ['node', 'options', 'comment', 'taxonomy', 'forum'];
+  public static $modules = ['node', 'options', 'comment', 'taxonomy', 'history', 'forum'];
 
   /**
    * Tests the forum validation constraints.
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
index 302c3d1aee..26f56ee2cd 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
@@ -17,7 +17,7 @@ class MigrateForumConfigsTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['comment', 'forum', 'taxonomy'];
+  public static $modules = ['comment', 'forum', 'history', 'taxonomy'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
index 6f5d48c1dd..6141d5700b 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
@@ -22,6 +22,7 @@ class MigrateForumTest extends MigrateNodeTestBase {
   public static $modules = [
     'comment',
     'forum',
+    'history',
     'menu_ui',
     'taxonomy',
   ];
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
index cd1c7fc3ea..c1b33410ed 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
@@ -19,6 +19,7 @@ class MigrateForumSettingsTest extends MigrateDrupal7TestBase {
     'text',
     'node',
     'taxonomy',
+    'history',
     'forum',
   ];
 
diff --git a/core/modules/forum/tests/src/Unit/ForumManagerTest.php b/core/modules/forum/tests/src/Unit/ForumManagerTest.php
index 969bb71219..85b85f5c9a 100644
--- a/core/modules/forum/tests/src/Unit/ForumManagerTest.php
+++ b/core/modules/forum/tests/src/Unit/ForumManagerTest.php
@@ -56,6 +56,10 @@ public function testGetIndex() {
       ->disableOriginalConstructor()
       ->getMock();
 
+    $history_repository = $this->getMockBuilder('\Drupal\history\HistoryRepository')
+      ->disableOriginalConstructor()
+      ->getMock();
+
     $comment_manager = $this->getMockBuilder('\Drupal\comment\CommentManagerInterface')
       ->disableOriginalConstructor()
       ->getMock();
@@ -69,6 +73,7 @@ public function testGetIndex() {
         $translation_manager,
         $comment_manager,
         $entity_field_manager,
+        $history_repository,
       ])
       ->getMock();
 
diff --git a/core/modules/history/history.install b/core/modules/history/history.install
index 85e2fdabbf..635b21a707 100644
--- a/core/modules/history/history.install
+++ b/core/modules/history/history.install
@@ -6,22 +6,30 @@
  */
 
 use Drupal\Core\Database\Database;
+use Drupal\Core\Entity\EntityTypeInterface;
 
 /**
  * Implements hook_schema().
  */
 function history_schema() {
   $schema['history'] = [
-    'description' => 'A record of which {users} have read which {node}s.',
+    'description' => 'A record of which {users} have read which entities.',
     'fields' => [
       'uid' => [
-        'description' => 'The {users}.uid that read the {node} nid.',
+        'description' => 'The {users}.uid that read the {history}.entity_id entity.',
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
       ],
-      'nid' => [
-        'description' => 'The {node}.nid that was read.',
+      'entity_type' => [
+        'description' => 'The type of the entity that was read.',
+        'type' => 'varchar_ascii',
+        'not null' => TRUE,
+        'default' => '',
+        'length' => EntityTypeInterface::ID_MAX_LENGTH,
+      ],
+      'entity_id' => [
+        'description' => 'The ID of the entity that was read.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
@@ -34,9 +42,9 @@ function history_schema() {
         'default' => 0,
       ],
     ],
-    'primary key' => ['uid', 'nid'],
+    'primary key' => ['entity_type', 'uid', 'entity_id'],
     'indexes' => [
-      'nid' => ['nid'],
+      'history_entity' => ['entity_type', 'entity_id'],
     ],
   ];
 
@@ -88,3 +96,70 @@ function history_update_8101() {
   ];
   $schema->addIndex('history', 'nid', ['nid'], $spec);
 }
+
+/**
+ * Change {history}.nid to {history}.entity_id and add {history}.entity_type.
+ */
+function history_update_8801() {
+  $database = Database::getConnection();
+  $schema = $database->schema();
+  $schema->dropPrimaryKey('history');
+  $schema->dropIndex('history', 'nid');
+  $schema->changeField('history', 'nid', 'entity_id', [
+    'description' => 'The ID of the entity that was read.',
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+  ]);
+  $schema->addField('history', 'entity_type', [
+    'description' => 'The type of the entity that was read.',
+    'type' => 'varchar_ascii',
+    'not null' => TRUE,
+    'default' => '',
+    'length' => EntityTypeInterface::ID_MAX_LENGTH,
+  ]);
+
+  // Set default value for {history}.entity_type.
+  $database->update('history')
+    ->fields(['entity_type' => 'node'])
+    ->execute();
+
+  $schema->addPrimaryKey('history', ['entity_type', 'uid', 'entity_id']);
+  $spec = [
+    'description' => 'A record of which {users} have read which entities.',
+    'fields' => [
+      'uid' => [
+        'description' => 'The {users}.uid that read the {history}.entity_id entity.',
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+      'entity_type' => [
+        'description' => 'The type of the entity that was read.',
+        'type' => 'varchar_ascii',
+        'not null' => TRUE,
+        'default' => '',
+        'length' => EntityTypeInterface::ID_MAX_LENGTH,
+      ],
+      'entity_id' => [
+        'description' => 'The ID of the entity that was read.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+      'timestamp' => [
+        'description' => 'The Unix timestamp at which the read occurred.',
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+    ],
+    'primary key' => ['entity_type', 'uid', 'entity_id'],
+    'indexes' => [
+      'history_entity' => ['entity_type', 'entity_id'],
+    ],
+  ];
+  $schema->addIndex('history', 'history_entity', ['entity_type', 'entity_id'], $spec);
+}
diff --git a/core/modules/history/history.module b/core/modules/history/history.module
index 3f73c2dc02..9a739cb049 100644
--- a/core/modules/history/history.module
+++ b/core/modules/history/history.module
@@ -14,7 +14,9 @@
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\history\HistoryRenderCallback;
+use Drupal\node\Entity\Node;
 use Drupal\user\UserInterface;
+use Drupal\Core\Session\AccountInterface;
 
 /**
  * Entities changed before this time are always shown as read.
@@ -45,10 +47,12 @@ function history_help($route_name, RouteMatchInterface $route_match) {
  * @return int
  *   If a node has been previously viewed by the user, the timestamp in seconds
  *   of when the last view occurred; otherwise, zero.
+ *
+ * @deprecated Use \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead.
  */
 function history_read($nid) {
-  $history = history_read_multiple([$nid]);
-  return $history[$nid];
+  $timestamps = \Drupal::service('history.repository')->getLastViewed('node', [$nid], \Drupal::currentUser());
+  return $timestamps[$nid];
 }
 
 /**
@@ -61,37 +65,11 @@ function history_read($nid) {
  *   Array of timestamps keyed by node ID. If a node has been previously viewed
  *   by the user, the timestamp in seconds of when the last view occurred;
  *   otherwise, zero.
+ *
+ * @deprecated Use \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead.
  */
 function history_read_multiple($nids) {
-  $history = &drupal_static(__FUNCTION__, []);
-
-  $return = [];
-
-  $nodes_to_read = [];
-  foreach ($nids as $nid) {
-    if (isset($history[$nid])) {
-      $return[$nid] = $history[$nid];
-    }
-    else {
-      // Initialize value if current user has not viewed the node.
-      $nodes_to_read[$nid] = 0;
-    }
-  }
-
-  if (empty($nodes_to_read)) {
-    return $return;
-  }
-
-  $result = \Drupal::database()->query('SELECT nid, timestamp FROM {history} WHERE uid = :uid AND nid IN ( :nids[] )', [
-    ':uid' => \Drupal::currentUser()->id(),
-    ':nids[]' => array_keys($nodes_to_read),
-  ]);
-  foreach ($result as $row) {
-    $nodes_to_read[$row->nid] = (int) $row->timestamp;
-  }
-  $history += $nodes_to_read;
-
-  return $return + $nodes_to_read;
+  return \Drupal::service('history.repository')->getLastViewed('node', $nids, \Drupal::currentUser());
 }
 
 /**
@@ -99,37 +77,26 @@ function history_read_multiple($nids) {
  *
  * @param $nid
  *   The node ID that has been read.
- * @param $account
+ * @param \Drupal\Core\Session\AccountInterface $account
  *   (optional) The user account to update the history for. Defaults to the
  *   current user.
+ *
+ * @deprecated Use \Drupal\history\HistoryRepositoryInterface::updateLastViewed() instead.
  */
-function history_write($nid, $account = NULL) {
+function history_write($nid, AccountInterface $account = NULL) {
 
   if (!isset($account)) {
     $account = \Drupal::currentUser();
   }
-
-  if ($account->isAuthenticated()) {
-    \Drupal::database()->merge('history')
-      ->keys([
-        'uid' => $account->id(),
-        'nid' => $nid,
-      ])
-      ->fields(['timestamp' => REQUEST_TIME])
-      ->execute();
-    // Update static cache.
-    $history = &drupal_static('history_read_multiple', []);
-    $history[$nid] = REQUEST_TIME;
-  }
+  $node = Node::load($nid);
+  \Drupal::service('history.repository')->updateLastViewed($node, $account);
 }
 
 /**
  * Implements hook_cron().
  */
 function history_cron() {
-  \Drupal::database()->delete('history')
-    ->condition('timestamp', HISTORY_READ_LIMIT, '<')
-    ->execute();
+  \Drupal::service('history.repository')->purge();
 }
 
 /**
@@ -154,9 +121,7 @@ function history_node_view_alter(array &$build, EntityInterface $node, EntityVie
  * Implements hook_ENTITY_TYPE_delete() for node entities.
  */
 function history_node_delete(EntityInterface $node) {
-  \Drupal::database()->delete('history')
-    ->condition('nid', $node->id())
-    ->execute();
+  \Drupal::service('history.repository')->deleteByEntity($node);
 }
 
 /**
@@ -165,9 +130,7 @@ function history_node_delete(EntityInterface $node) {
 function history_user_cancel($edit, UserInterface $account, $method) {
   switch ($method) {
     case 'user_cancel_reassign':
-      \Drupal::database()->delete('history')
-        ->condition('uid', $account->id())
-        ->execute();
+      \Drupal::service('history.repository')->deleteByUser($account);
       break;
   }
 }
@@ -176,9 +139,7 @@ function history_user_cancel($edit, UserInterface $account, $method) {
  * Implements hook_ENTITY_TYPE_delete() for user entities.
  */
 function history_user_delete($account) {
-  \Drupal::database()->delete('history')
-    ->condition('uid', $account->id())
-    ->execute();
+  \Drupal::service('history.repository')->deleteByUser($account);
 }
 
 /**
diff --git a/core/modules/history/history.services.yml b/core/modules/history/history.services.yml
new file mode 100644
index 0000000000..bd0549fbb5
--- /dev/null
+++ b/core/modules/history/history.services.yml
@@ -0,0 +1,6 @@
+services:
+  history.repository:
+    class: Drupal\history\HistoryRepository
+    arguments: ['@database', '@datetime.time']
+    tags:
+      - { name: backend_overridable }
diff --git a/core/modules/history/history.views.inc b/core/modules/history/history.views.inc
index 60c95cd868..4df607754f 100644
--- a/core/modules/history/history.views.inc
+++ b/core/modules/history/history.views.inc
@@ -22,8 +22,9 @@ function history_views_data() {
     'node_field_data' => [
       'table' => 'history',
       'left_field' => 'nid',
-      'field' => 'nid',
+      'field' => 'entity_id',
       'extra' => [
+        ['field' => 'entity_type', 'value' => 'node'],
         ['field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE],
       ],
     ],
diff --git a/core/modules/history/src/Controller/HistoryController.php b/core/modules/history/src/Controller/HistoryController.php
index c6a4834903..218a164d6c 100644
--- a/core/modules/history/src/Controller/HistoryController.php
+++ b/core/modules/history/src/Controller/HistoryController.php
@@ -2,11 +2,13 @@
 
 namespace Drupal\history\Controller;
 
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Drupal\Core\Controller\ControllerBase;
+use Drupal\history\HistoryRepositoryInterface;
 use Drupal\node\NodeInterface;
 
 /**
@@ -14,13 +16,39 @@
  */
 class HistoryController extends ControllerBase {
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
+  /**
+   * Constructs a HistoryController object.
+   *
+   * @param \Drupal\history\HistoryRepositoryInterface $history_repository
+   *   The history repository service.
+   */
+  public function __construct(HistoryRepositoryInterface $history_repository) {
+    $this->historyRepository = $history_repository;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('history.repository')
+    );
+  }
+
   /**
    * Returns a set of nodes' last read timestamps.
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
    *   The request of the page.
    *
-   * @return Symfony\Component\HttpFoundation\JsonResponse
+   * @return \Symfony\Component\HttpFoundation\JsonResponse
    *   The JSON response.
    */
   public function getNodeReadTimestamps(Request $request) {
@@ -32,7 +60,7 @@ public function getNodeReadTimestamps(Request $request) {
     if (!isset($nids)) {
       throw new NotFoundHttpException();
     }
-    return new JsonResponse(history_read_multiple($nids));
+    return new JsonResponse($this->historyRepository->getLastViewed('node', $nids, $this->currentUser()));
   }
 
   /**
@@ -42,6 +70,8 @@ public function getNodeReadTimestamps(Request $request) {
    *   The request of the page.
    * @param \Drupal\node\NodeInterface $node
    *   The node whose "last read" timestamp should be updated.
+   *
+   * @return \Symfony\Component\HttpFoundation\JsonResponse
    */
   public function readNode(Request $request, NodeInterface $node) {
     if ($this->currentUser()->isAnonymous()) {
@@ -49,9 +79,10 @@ public function readNode(Request $request, NodeInterface $node) {
     }
 
     // Update the history table, stating that this user viewed this node.
-    history_write($node->id());
+    $this->historyRepository->updateLastViewed($node, $this->currentUser());
 
-    return new JsonResponse((int) history_read($node->id()));
+    $timestamps = $this->historyRepository->getLastViewed('node', [$node->id()], $this->currentUser());
+    return new JsonResponse($timestamps[$node->id()]);
   }
 
 }
diff --git a/core/modules/history/src/HistoryRenderCallback.php b/core/modules/history/src/HistoryRenderCallback.php
index c6a92eda68..982709d397 100644
--- a/core/modules/history/src/HistoryRenderCallback.php
+++ b/core/modules/history/src/HistoryRenderCallback.php
@@ -20,7 +20,8 @@ class HistoryRenderCallback implements RenderCallbackInterface {
    */
   public static function lazyBuilder($node_id) {
     $element = [];
-    $element['#attached']['drupalSettings']['history']['lastReadTimestamps'][$node_id] = (int) history_read($node_id);
+    $timestamps = \Drupal::service('history.repository')->getLastViewed('node', [$node_id], \Drupal::currentUser());
+    $element['#attached']['drupalSettings']['history']['lastReadTimestamps'][$node_id] = (int) $timestamps[$node_id];
     return $element;
   }
 
diff --git a/core/modules/history/src/HistoryRepository.php b/core/modules/history/src/HistoryRepository.php
new file mode 100644
index 0000000000..49441dc023
--- /dev/null
+++ b/core/modules/history/src/HistoryRepository.php
@@ -0,0 +1,175 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\history\HistoryRepository.
+ */
+
+namespace Drupal\history;
+
+use Drupal\Core\Database\Connection;
+use Drupal\Component\Datetime\TimeInterface;
+use Drupal\Core\DependencyInjection\DependencySerializationTrait;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Provides history repository service.
+ */
+class HistoryRepository implements HistoryRepositoryInterface {
+  use DependencySerializationTrait {
+    __wakeup as defaultWakeup;
+    __sleep as defaultSleep;
+  }
+
+  /**
+   * An array of history IDs keyed by entity type and entity id.
+   *
+   * @var array
+   */
+  protected $history = [];
+
+  /**
+   * The database connection.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * The time service.
+   *
+   * @var \Drupal\Component\Datetime\TimeInterface
+   */
+  protected $time;
+
+  /**
+   * Constructs the history repository service.
+   *
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The database connection.
+   * @param \Drupal\Component\Datetime\TimeInterface $time
+   *   The time service.
+   */
+  public function __construct(Connection $connection, TimeInterface $time) {
+    $this->connection = $connection;
+    $this->time = $time;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getLastViewed($entity_type, $entity_ids, AccountInterface $account) {
+    $entities = [];
+
+    $entities_to_read = [];
+    foreach ($entity_ids as $entity_id) {
+      if (isset($this->history[$entity_type][$account->id()][$entity_id])) {
+        $entities[$entity_id] = $this->history[$entity_type][$account->id()][$entity_id];
+      }
+      else {
+        $entities_to_read[$entity_id] = 0;
+      }
+    }
+
+    if (empty($entities_to_read)) {
+      return $entities;
+    }
+
+    $result = $this->connection->select('history', 'h')
+      ->fields('h', ['entity_id', 'timestamp'])
+      ->condition('uid', $account->id())
+      ->condition('entity_type', $entity_type)
+      ->condition('entity_id', array_keys($entities_to_read), 'IN')
+      ->execute();
+
+    foreach ($result as $row) {
+      $entities_to_read[$row->entity_id] = (int) $row->timestamp;
+    }
+    if (!isset($this->history[$entity_type][$account->id()])) {
+      $this->history[$entity_type][$account->id()] = [];
+    }
+    $this->history[$entity_type][$account->id()] += $entities_to_read;
+
+    return $entities + $entities_to_read;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function updateLastViewed(EntityInterface $entity, AccountInterface $account) {
+    if ($account->isAuthenticated()) {
+      $this->connection->merge('history')
+        ->keys([
+          'uid' => $account->id(),
+          'entity_id' => $entity->id(),
+          'entity_type' => $entity->getEntityTypeId(),
+        ])
+        ->fields(['timestamp' => $this->time->getRequestTime()])
+        ->execute();
+      // Update cached value.
+      $this->history[$entity->getEntityTypeId()][$account->id()][$entity->id()] = $this->time->getRequestTime();
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function purge() {
+    $this->connection->delete('history')
+      ->condition('timestamp', HISTORY_READ_LIMIT, '<')
+      ->execute();
+    // Clean static cache.
+    $this->resetCache();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function deleteByUser(AccountInterface $account) {
+    $this->connection->delete('history')
+      ->condition('uid', $account->id())
+      ->execute();
+    // Clean static cache.
+    $this->resetCache();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function deleteByEntity(EntityInterface $entity) {
+    $this->connection->delete('history')
+      ->condition('entity_id', $entity->id())
+      ->condition('entity_type', $entity->getEntityTypeId())
+      ->execute();
+    // Clean static cache.
+    $this->resetCache();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function resetCache() {
+    $this->history = [];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __sleep() {
+    $vars = $this->defaultSleep();
+    // Do not serialize static cache.
+    unset($vars['history']);
+    return $vars;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __wakeup() {
+    $this->defaultWakeup();
+    // Initialize static cache.
+    $this->history = [];
+  }
+
+}
diff --git a/core/modules/history/src/HistoryRepositoryInterface.php b/core/modules/history/src/HistoryRepositoryInterface.php
new file mode 100644
index 0000000000..c50787e88b
--- /dev/null
+++ b/core/modules/history/src/HistoryRepositoryInterface.php
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\history\HistoryRepositoryInterface.
+ */
+
+namespace Drupal\history;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines an interface to store and retrieve a last view timestamp of entities.
+ */
+interface HistoryRepositoryInterface {
+
+  /**
+   * Retrieves the timestamp for the current user's last view of the entities.
+   *
+   * @param string $entity_type
+   *   The entity type.
+   * @param array $entity_ids
+   *   The entity IDs.
+   * @param \Drupal\Core\Session\AccountInterface $account
+   *   The user account to get the history for.
+   *
+   * @return array
+   *   Array of timestamps keyed by entity ID. If a entity has been previously
+   *   viewed by the user, the timestamp in seconds of when the last view
+   *   occurred; otherwise, zero.
+   */
+  public function getLastViewed($entity_type, $entity_ids, AccountInterface $account);
+
+  /**
+   * Updates 'last viewed' timestamp of the entity for the user account.
+   *
+   * @param \Drupal\Core\Entity\EntityInterface $entity
+   *   The entity that history should be updated.
+   * @param \Drupal\Core\Session\AccountInterface $account
+   *   The user account to update the history for.
+   */
+  public function updateLastViewed(EntityInterface $entity, AccountInterface $account);
+
+  /**
+   * Purges outdated history.
+   */
+  public function purge();
+
+  /**
+   * Deletes the history for the given user account.
+   *
+   * @param \Drupal\Core\Session\AccountInterface $account
+   *   The user account to purge history.
+   */
+  public function deleteByUser(AccountInterface $account);
+
+  /**
+   * Deletes the history for the given entity.
+   *
+   * @param \Drupal\Core\Entity\EntityInterface $entity
+   *   The entity that history should be deleted.
+   */
+  public function deleteByEntity(EntityInterface $entity);
+
+}
diff --git a/core/modules/history/tests/src/Functional/Update/HistoryUpdateTest.php b/core/modules/history/tests/src/Functional/Update/HistoryUpdateTest.php
new file mode 100644
index 0000000000..fd051c3ebb
--- /dev/null
+++ b/core/modules/history/tests/src/Functional/Update/HistoryUpdateTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\Tests\history\Functional\Update;
+
+use Drupal\FunctionalTests\Update\UpdatePathTestBase;
+
+/**
+ * Tests update functions for the History module.
+ *
+ * @group Update
+ * @group legacy
+ */
+class HistoryUpdateTest extends UpdatePathTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['history'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setDatabaseDumpFiles() {
+    $this->databaseDumpFiles = [
+      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
+    ];
+  }
+
+  /**
+   * Tests changing nid to entity_id and adding an entity_type field to the history table.
+   *
+   * @see history_update_8801()
+   */
+  public function testUpdateHookN() {
+    $schema = \Drupal::database()->schema();
+
+    // Run updates.
+    $this->runUpdates();
+
+    // Ensure fields were added.
+    $this->assertTrue($schema->fieldExists('history', 'entity_type'));
+    $this->assertTrue($schema->fieldExists('history', 'entity_id'));
+    // Ensure field was removed.
+    $this->assertFalse($schema->fieldExists('history', 'nid'));
+
+    $this->assertTrue($schema->indexExists('history', 'history_entity'));
+    $this->assertFalse($schema->indexExists('history', 'nid'));
+  }
+
+}
diff --git a/core/modules/history/tests/src/Kernel/HistoryLegacyTest.php b/core/modules/history/tests/src/Kernel/HistoryLegacyTest.php
index 82d0b3345f..756f3feed9 100644
--- a/core/modules/history/tests/src/Kernel/HistoryLegacyTest.php
+++ b/core/modules/history/tests/src/Kernel/HistoryLegacyTest.php
@@ -54,7 +54,7 @@ public function testHistoryAttachTimestamp() {
     history_write(1);
 
     $render = history_attach_timestamp(1);
-    $this->assertEquals(REQUEST_TIME, $render['#attached']['drupalSettings']['history']['lastReadTimestamps'][1]);
+    $this->assertEquals(\Drupal::time()->getRequestTime(), $render['#attached']['drupalSettings']['history']['lastReadTimestamps'][1]);
   }
 
 }
diff --git a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
index f66ce52476..7f9b151c35 100644
--- a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
+++ b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
@@ -72,14 +72,16 @@ public function testHandlers() {
     $connection->insert('history')
       ->fields([
         'uid' => $account->id(),
-        'nid' => $nodes[0]->id(),
+        'entity_id' => $nodes[0]->id(),
+        'entity_type' => 'node',
         'timestamp' => REQUEST_TIME - 100,
       ])->execute();
 
     $connection->insert('history')
       ->fields([
         'uid' => $account->id(),
-        'nid' => $nodes[1]->id(),
+        'entity_id' => $nodes[1]->id(),
+        'entity_type' => 'node',
         'timestamp' => REQUEST_TIME + 100,
       ])->execute();
 
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
index 1a340e4e43..9612bd5e16 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
@@ -39,6 +39,7 @@ class MigrationPluginListTest extends KernelTestBase {
     'file',
     'filter',
     'forum',
+    'history',
     'image',
     'language',
     'locale',
