There are A LOT of different ways to deploy Elixir/Phoenix applications. I want to fill a gap in the current literature: how do you deploy a Phoenix web app to a single Linux server optimizing for cost effectiveness, control, and simplicity, while using modern Elixir tools like releases to achieve zero-downtime deploys without hot code upgrading?
I’m going to walk through a deployment strategy that can take you start-to-finish with a full-featured Phoenix web app running on a free-forever Google Cloud Platform Compute Engine instance.
This setup is completely free, and when you have more traffic the cost of scaling on raw GCP instances is a lot cheaper than on platform-as-a-service offerings (Heroku, Gigalixir, Render, etc). And, you’re in full control of the system so you don’t have to work around any fixed limitations. Scaling can be as simple as upgrading the specs of the instance when it can’t keep up anymore. …
I want to share some thoughts and opinions about Elixir GenServers for developers writing web applications (probably with Phoenix).
This isn’t a technical deep dive on GenServers, it’s just some of my thoughts about them from writing web apps in Elixir / Phoenix over the last couple years.
There’s really just one type of GenServer that’s ever been a great fit for a problem I’m facing, and I come across the problem in almost every app I build: the need for recurring background tasks.
For example, in an app I worked on recently I needed to run a job every 10 minutes to pull data from a system of record through one API, and then transform and update some records through another API. …
Are not as difficult as they seem
When I’m working with a new Phoenix app (written in Elixir), I often come across the following situation. I happened to run into it last night on a side-project I’m building called Remind Me (which you should definitely check out, it’s free and it will help you stay on top of a whole class of to-do’s that often fall through the cracks), so I decided to write up my thoughts on the subject. Here’s the issue (with fake resource names for illustration):
User
which has_many TextMessageItem
‘s and has_one…
I want to take some of the intimidation out of recursive functions.
The word “recursive” used to make my mind shut off the way that math terms in highschool did like “quadradic functions” or “polynomials”.
Any time I was reading something that involved recursion, I went looking somewhere else for an easier solution.
Now, I look at them as a tool that is sometimes easier to wrap my head around than digging into some of the reduce
functions in the Enum
module.
Ok so how can I convince you that recursive functions aren’t scary?
Let’s look at a normal function:
def normal_function(number) do
number + 1…
Cleaning up messy controller actions
I build a lot of apps with Phoenix, and I sometimes run into a problem where I need to pass a lot of variables from a controller down to the view / template.
When you only have one or two variables, here’s what the controller action looks like:
def index(conn, _params) do
users = Accounts.list_users()
render(conn, "index.html", users: users)
end
The relevant part is users: users
in the render/3
function, which is a keyword list of of key/value pairs that will be available in the template. …
This is a continuation of Learning to Code the Easy Way (Part 1).
We ended by talking about a program that comes with your Mac called “Terminal”. It’s basically a little white box that pops up that you can write words in, and it does stuff on your computer like install programs and run code.
Developers use Terminal to connect to computers in remote locations, to install programming languages, and to run commands that start and stop programs. …
Learning to write software can be hard. One of the things that can be the most challenging for a beginner is the mounds of free information online, because most of it assumes that you already know a bunch of fundamentals and you get lost if you don’t. I will show you how to get from no coding experience at all to having a working website that can receive, store, and display information. We’re going to use a programming language called Elixir, and a website framework that uses Elixir called Phoenix.
Elixir is a beautiful programming language, and will allow you to keep things very simple in the beginning but provides very powerful and helpful tools that you can leverage as you gain experience. The language is also designed very intentionally, and will push you towards writing good code as you learn more and do more with it. …
Today I discovered an awesome property of Elixir maps that let me reduce the time of a matching operation on large datasets from about 30+ minutes to less than a second.
I was working on a project to take about 10,000 “leads” records with basic info like First Name, Last Name, and Email and compare them to an existing set of about 10,000 “contacts” records with a more expansive data set, trying to find any “leads” that match a “contact” by email address. When a match is found, the “lead” is merged into the existing “contact”.
I’ll recreate the situation with some code to generate the big data…
Learning to write software can be hard. One of the things that can be the most challenging for a beginner is the mounds of free information online, because most of it assumes that you already know a bunch of fundamentals and you get lost if you don’t. I will show you how to get from no coding experience at all to having a working website that can receive, store, and display information. We’re going to use a programming language called Elixir, and a website framework that uses Elixir called Phoenix.
Elixir is a beautiful programming language, and will allow you to keep things very simple in the beginning but provides very powerful and helpful tools that you can leverage as you gain experience. The language is also designed very intentionally, and will push you towards writing good code as you learn more and do more with it. …
About