Up to this point, my experience with Erlang professionally has mostly been with ejabberd. I’ve created many ejabberd modules and have had to modify ejabberd core for certain projects (sometimes heavily). Now that my current client work at CitrusByte is over, I’ve been notified I will be working on a fairly customized Erlang/OTP application. Without going into too much detail, I have just began seriously looking at EUnit.
This is the fourth article in the otp introduction series. If you haven’t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. If you are a quick learner, you can view the currently completed erlang files so far: eb_server.erl, eb_event_manager.erl, eb_withdrawal_handler.erl, and eb_atm.erl.
The Scenario: The thing that makes us feel good about banks and ATMs is that they are always there. We can deposit and get money whenever want, 24 hours a day, using an ATM. Or we can go into any bank branch when they’re open, and know we have complete access to our funds. To achieve this security, we need to make sure that our system to run ErlyBank always stays working: the processes must always be running. ErlyBank has commissioned us to achieve this goal. 100% uptime! (Or as close to that as we can get)
The Result: Using an OTP supervisor, we will create a process whose responsibility it is to watch the running processes and make sure they stay up.
This is the third article in the otp introduction series. If you haven’t yet, I recommend you start with the first article which talks about gen_server and lays the foundation for our bank system. Again, if you’re a quick learner, you can look at the completed eb_atm.erl and eb_server.erl here.
The Scenario: With central server and ATM software in place, ErlyBank is started to feel good about their technological foundation. But as a security measure, one of their competitors, they’d like a system implemented which dispatches notifications when a withdrawal over a certain amount is executed. They want the ability to change the withdrawal notification amount threshold during runtime. They’ve chosen to hire us to streamline this into the current system software.
The Result: We’ll create an event-based notification system using gen_event. This will give us a base foundation for creating more notifications in the future, while allowing us to easily plug-in to the current server software.
This is the second article in my Erlang/OTP introduction series. If you haven’t yet, I recommend you read the first article which talks about gen_server and lays the foundation for our bank system before moving onto this article. That being said, if you’re a quick learner, you can look at the completed server file and continue from there.
The Scenario: We delivered ErlyBank’s server to them and they were very pleased. But this is the 21st century so they also need a secure and easy to use ATM system, so they’ve asked that we extend the server and also create their ATM backend. User accounts are to be protected with a four-digit PIN. From the ATM you should be able to log in to a previously existing account, and deposit or withdraw funds. There is no need to create a pretty user interface on top of the ATM backend, they have another team doing that.
The Result: First, we’ll extend the server software to hold a PIN for accounts, and add an authorization call to it. Then, we’ll use gen_fsm to create the ATM backend. We’ll rely on the server to do all the data validation.
As always, click read more to get started, if you haven’t already…
This is the first article in a series of articles introducing all the concepts pertaining to Erlang/OTP. In order to find all these articles later, they are tagged with a unique tag to the series: otp introduction. As promised in my initial introduction to OTP, we will be making a server to handle the fake bank accounts of people at “ErlyBank” (Yes, I enjoy coming up with silly names).
The Scenario: ErlyBank is just starting and they want to start off on the right foot by creating a scalable system for managing the bank accounts of its important customer-base. Having heard about the powers of Erlang, we have been hired to do that! But to test us out, they first want a simple server to handle the creation and destruction of accounts, depositing money, and withdrawing money. They just want a prototype, not something they’ll actually be putting into production.
The Result: We will create a simple server and client to do everything they asked using gen_server. Since its just a prototype, we’ll store the account information in memory for now. The accounts will only be referenced by name, no other information is necessary to create an account. And of course we’ll have validation on withdrawals and deposits.
Note: Before beginning this series, I am assuming you have a basic knowledge of the Erlang syntax. If not, I recommend reading my compendium of beginner erlang resources to find a place you can learn Erlang.
If you’re ready, click read more below to get started! (Unless you’re viewing the whole article already )
Many people refer to Erlang as “Erlang/OTP.” OTP stands for Open Telecom Platform, and is more or less a set of libraries which come packaged with Erlang. They consist of Erlang behaviors (or behaviours, technically) for writing servers, finite state machines, event managers. But that is not all, OTP also encompasses the application behavior which allows programmers to package their Erlang code into a single “application.” And the supervisor behavior allows programmers to create a hierarchy of processes, where if one process dies, it will be restarted.
OTP is much too complex of a thing to explain in a single article, and I will not attempt to do so here. Instead, I will be making this a series of articles spanning a couple weeks.
Why should I learn about Erlang/OTP?
The platform which comes with Erlang gives you a rich and very generalized set of libraries and behaviors to easily create highly available, fault tolerant, hot code swapping ready systems. The following is a basic list of what it gives you “for free:”
- Generic server, finite state machine, and event manager behaviors
- Standardized application structure
- Hot swappable code
- Supervisor Trees so your processes always stay up
Therefore, by learning OTP, you will not only gain the knowledge and ability to create powerful Erlang systems, but you’ll be able to readily jump into other open source projects and learn from them, since they follow the same general structure.
If you know the general Erlang syntax, then you’re ready to jump in and begin learning about Erlang/OTP!
Click read more below to read the rest of this introduction
It seems like just yesterday I was just starting to dive into Erlang. Actually, it was only a few months ago, and Erlang resources were hard to come by! In addition to the lack of resources, there were a lack of blogs to help me along the way. The main purpose of this blog is to track my findings with Erlang, especially using it in a professional world, and help others learn what I have learned. As an added bonus, I’ll probably learn things from readers along the way, too.
To kick this blog off, I’ve compiled a list of resources that I used to jump into Erlang, and some additional resources I’ve found recently. They are in order of difficulty based on my personal opinion, to help you climb the Erlang mountain!
Before we even get started, you must watch Erlang: The Movie. Maybe its just because I’m such a nerd, but that movie hyped me up about Erlang. Once you have finished watching that… moving on…
The Resource List
The first two resources are not free, but if you are going to spend any money on learning Erlang, please keep in mind that you’re investing in a very powerful, unique language which fills a much needed role in the computing world. As for personal opinion, I highly recommend Joe Armstrong’s book. It is very broad and introduces you to the whole spectrum of Erlang which will provide you with a solid foundation that can jump-start your Erlang career.
- Programming Erlang: Software for a Concurrent World by Joe Armstrong
- Erlang In Practice Screencasts by Kevin Smith
- Official Getting Started Doc - If you’ve read Armstrong’s book, you may comfortably skip this.
At this time I’d like to point out that you should have a complete understanding of the syntax and general workings of Erlang the language. But learning the syntax is fairly useless if you don’t know the powerful tools Erlang gives you out of the box, and the general conventions you should follow while programming in Erlang. The following resources begin this journey…
- Official Programming Examples - Gives a few examples of how to achieve common tasks. At the very least, you should try to write these yourself to get used to the style of Erlang.
- OTP Design Principles - You will use the OTP behaviors and modules a lot so you should take your time to learn the right way to use them.
- Erlang Man Pages - Okay… don’t actually read the entire thing. But bookmark this page! And at least read the big-name modules through, such as the OTP modules, application, erlang, etc. This is an invaluable resource while you’re working in Erlang trying to remember a method or lookup a method you don’t recognize.
- Paul Nelson’s EUnit-Based Tutorials - Based on comments of this post, I’ve looked through and recommend Paul Nelson’s tutorials. He teaches Erlang through EUnit-focused tutorials. A great way to get acquainted with both the language and unit testing in Erlang.
Now you know Erlang syntax, general OTP usage, and you should have an idea of what Erlang programming “style” is. You should also know how to use EUnit to test your code.
Unfortunately, those are really all the useful beginner readable resources… really. If you know anymore that are useful, please comment and I’ll gladly add them to the list.
“What do I do now?”
You know the syntax, you know the basic modules, you know basic OTP, and you know some style, what do you do now? Easy! Check out some open source applications:
- ejabberd - A jabber chat server. It will take a couple hours to really understand the source but my first job was hacking up ejabberd and I learned more than I ever thought possibly by reading only through this application. You should too!
- RabbitMQ - Another messaging server, this time written on top of AMQP. Again, takes a few hours to dive in, but once you’re in, the knowledge you’ll gain is priceless.
That’s all I’ve got! If you have any questions, comments, or have any additions to make to the list, comment and I’ll gladly add them. Good luck!