What is conn and changeset?

Hi there!

Let’s assume I’m a total newbie here (I came from non-ruby/rails background), and can someone explain in simple English, what is “conn” and “changeset” in elixir/phoenix?

Yes, I did read the doc but I still don’t quite understand

Any help would be greatly appreciated, thanks! :slight_smile:


conn represents the user’s request and then the response, as I understand it in my head. They send it to the server, and you transform it as it goes along to give them what they want. It carries cookies, request info, params, etc…

A changeset is something Ecto gives you to model a… model. If you look in a boilerplate generated model, you’ll also see a changeset function. What this does is takes the struct of the model, and casts it into an Ecto changeset that has information about whether it is valid, what was changed, and whatnot. It gives you an opportunity to work with it, and it’s what you actually give to Ecto to insert/change/delete something from the database.

This is how I understand these two things anyway. There’s probably a lot still I’m missing. Looking forward to more answers.


terakilobyte is correct. A ‘conn’ is just data; it contains all the information the server knows about the current user('s computer) and the request they made, and how to reach that user once the server has computed something for them, be it through a websocket or through a plain HTTP answer.

a ‘changeset’ is literally what it says on the tin: It is a set of (proposed) changes to an existing data model. It is useful to pass this around instead of updating the model directly because this way:

a) only a single database request is required once all new values of the different properties we want to change are computed
b) we can check the combination of these new values with the other proposed changes, and see if they can be considered ‘valid’(i. e. if they make sense in our application) to enhance the integrity of the stored data.


For more information, a conn/connection is the Plug structure that is passed down the Plug pipeline, where each Plug operates on or does something with the conn then it is continued to be passed on until it hits your last area, the controller/socket. The Plug is generated by the root Phoenix/Cowboy Plug when an incoming socket connection is established (a webpage request), then is passed up the line getting transformed, cleaned up, routed properly, etc… :slight_smile:


@terakilobyte @Qqwy @OvermindDL1

Really apreciate the answers :smiley:
Thank you very much, you are all awesome!