     db
   end
 
-  defp register_state(:ok, db), do: Map.put(db, :state, :loaded)
-  defp register_state({:error, _} = err, db), do: Map.put(db, :state, err)
+  defp prepare_ets_state() do
+    case :ets.info(@ets_state_name) do
+      :undefined ->
+        _ = :ets.new(@ets_state_name, @ets_state_opts)
+        :ok
+
+      _ ->
+        :ok
+    end
+  end
+
+  defp register_state(:ok, db), do: register_state(:loaded, db)
+
+  defp register_state(state, db) do
+    db = Map.put(db, :state, state)
+    true = :ets.insert(@ets_state_name, {db[:id], db})
+
+    db
+  end
 
   defp unload_database(nil), do: :ok
 
   defp unload_database(%{adapter: adapter} = database) do
-    case function_exported?(adapter, :unload_database, 1) do
-      true -> adapter.unload_database(database)
-      false -> :ok
-    end
+    :ok =
+      case function_exported?(adapter, :unload_database, 1) do
+        true -> adapter.unload_database(database)
+        false -> :ok
+      end
+
+    true = :ets.delete(@ets_state_name, database[:id])
+
+    :ok
   end
 end

  defp load_error_message({:config, :unknown_adapter}), do: "unknown adapter configuration"
  defp load_error_message(reason), do: inspect(reason)

  defp maybe_log_error(%{state: :loaded} = db), do: db

  defp maybe_log_error(%{state: {:error, reason}} = db) do

  require Logger

  alias Geolix.Database.Supervisor, as: DatabaseSupervisor

  @ets_state_name :geolix_database_loader
  @ets_state_opts [:named_table, :protected, :set, read_concurrency: true]

  # GenServer lifecycle

