Storing temporary data in ETS - for example, using ETS in a web wizard I'm learning the Elixir language and the Phoenix web framework. And I had an idea. What if, in a web wizard (multi-step form) scenario, I stored the intermediate data in a ETS table instead of the relational database?

So I wrote this controller:

defmodule PlayPhoenixWeb.ThingsController do
  use PlayPhoenixWeb, :controller
  require Logger
  @moduledoc false

  @form_ets :things_forms

  alias PlayPhoenixWeb.Router.Helpers, as: Routes
  alias PlayPhoenixWeb.Endpoint

  def step_1_display(conn, _params) do
    render(conn, "form_1.html")
  end

  def step_1_process(conn, params) do
    data = Map.take(params, ["name", "vcode"])
    key = make_key()
    write_data(key, data)
    Logger.debug inspect(data)
    redirect(conn, to: Routes.thing_form_2_path(Endpoint, :step_2_display, key))
  end

  def step_2_display(conn, %{"key" =&gt; key}) do
    render(conn, "form_2.html", key: key)
  end

  def step_2_process(conn, %{"key" =&gt; key} = params) do
    {:ok, data} = get_data(key)
    full_data = Map.take(params, ["description", "value"]) |&gt; Map.merge(data)
    # In production, processing full data would happen here
    Logger.debug inspect(full_data)
    redirect(conn, to: Routes.page_path(Endpoint, :index))
  end

  # This method is called by the Application on startup
  def init_ets(), do: :ets.new(@form_ets, [:public, :named_table])

  defp make_key(), do: :crypto.hash(:md5, DateTime.utc_now() |&gt; DateTime.to_iso8601) |&gt; :base64.encode

  defp get_data(key) do
    case :ets.lookup(@form_ets, key) do
      [{^key, value}] -&gt; {:ok, value}
      _ -&gt; {:not_found}
    end
  end

  defp write_data(key, data) do
    :ets.insert(@form_ets, {key, data})
  end

  defp delete_data(key), do: :ets.delete(@form_ets, key)

end


(It's purely for the sake of playing/research, and currently doesn't store or process any data).

Is this the Elixir way/the Phoenix way?

Thank you very much.
Yes, using ETS for this sort of temporary data is totally fine, as long as you realize of course that all that intermediate state is lost whenever you restart your server. In fact, if you dig into Phoenix and Elixir a bit, you will see a lot of ETS usage - it's not so much a thing you turn to in exceptional circumstances, but more a tool in the extensive toolbox at the same level of, say, GenServer.