What is ETS (Erlang Term Storage) in Elixir?
Answer
ETS (Erlang Term Storage) is an in-memory key-value store built into the BEAM, accessible from any process with no copying overhead (data is shared via references). Create a table: :ets.new(:my_cache, [:named_table, :public, read_concurrency: true]). Insert: :ets.insert(:my_cache, {:user_1, %{name: "Alice"}}). Lookup: :ets.lookup(:my_cache, :user_1). Types: :set (default, unique keys), :bag (multiple values per key), :ordered_set. Access types: :public (any process), :protected (only owner writes), :private. ETS is significantly faster than GenServer for read-heavy shared state because reads don't serialize through a single process mailbox. Use cases: caching database query results, rate limiting counters, session storage, compiled route tables. DETS: disk-based ETS for persistence. Mnesia: distributed database built on ETS for multi-node state.
Previous
How does hot code upgrading work in Elixir/Erlang?
Next
What is the Registry module in Elixir?
More Elixir Questions
View all →- Intermediate How do Elixir supervisors implement fault tolerance?
- Intermediate What is Phoenix Channels and how do WebSockets work in Elixir?
- Intermediate What is Elixir's concurrency model compared to threads?
- Intermediate What are Elixir behaviours?
- Intermediate What is Elixir's error handling approach?