Setting up Encryption at REST with Amazon RDS and PostgreSQL

In order to make sure our customer data is as safe as possible, we decided to implement encryption at rest. Although we tried a few different approaches, we finally settled on encrypting the database file system and everything related to it. As we are already using an Amazon PostgreSQL instance, and Amazon RDS supports database encryption at rest, we chose that option. As it often is in life, you can’t really flip a switch and encrypt a running instance. So we decided to dive into the documentation and find out how to do it as painlessly as possible.

_Mandatory disclaimer: this guide is intended for educational purposes only and if you somehow mess up your production data by following it, it’s not my fault._

How do you encrypt an unencrypted Amazon RDS instance then? Well, it’s a pretty simple and quite short procedure (this does depend on the amount of data you have, but it shouldn’t take you more than an hour for a 500GB instance)

Take a few minutes and make yourself a cup of coffee/tea/matcha, then come back and follow along this simple procedure.

1. To ensure that you don’t have any “new” data from users or background jobs you should put the application into maintenance mode and turn off all web and worker processes. It is also nice to announce a planned downtime weeks in advance, and do it when there are practically no users using the app. This probably won’t be a Wednesday morning, during business hours. You have your analytics, plan the thing in advance.
2. After the maintenance mode is on, and there is no chance of any database connections coming to the old unencrypted database, you can take a snapshot of it. Select the desired database from Amazon RDS \> Instances then go to Instance actions \> Take snapshot, be sure to give the snapshot a nice name (Daisy does sound nice, but I would go with app-production-decrypted or something descriptive).
3. Go to Snapshots and select the snapshot you’ve just created
4. Select Snapshot actions then Copy Snapshot
5. Select Enable Encryption in the encryption box and select the KMS key for the database you are encrypting (or let the system create an auto managed key, which I don’t recommend, because you will be using a master KMS key for all instances here, and not a per-instance one.)
6. Rename the old database instance to a new name, so the name won’t collide with the restored instance.
7. Restore the snapshot in the same way as you would do with a normal unencrypted snapshot by going to the Snapshots page, selecting a snapshot and selecting Restore Snapshot under Snapshot Actions. Obviously you want to give it the same name that the old database instance had (you don’t want to update those pesky configuration files with database connection strings).
8. Run your tests and assert that everything works, and only then turn on the web/worker services on. Take down the maintenance page, and reap the benefits of having encryption at rest.

While there are many ways to set up encryption at rest, and many variations on what falls under that term, this is just one of them that fits our model best. We did explore a few more encryption options, but all came with certain drawbacks when implemented within our architecture. Stay tuned for more AWS articles in the future.


When was the last time you’ve stopped and took a break? Not a weekend or 3-4 days, but a proper vacation. Something that lasts at least a week or two., a month if you are lucky. Some time for you to unwind, let go of everything, and relax.
There is still a hype about workaholism being great in todays culture. Working 100+ hours a week, never going on a vacation is a thing people see as something positive. Working yourself to death isn’t the most interesting way to die, at least not in my book.
I used to work 12 hour days, when I was starting with remote work, still working at a full time, on site job. I managed to do that for less than 6 months, with my productivity going down fast in the last months. Add onto that a baby, a family to take care of, and you can’t afford going bonkers over work.
Now I have a healthy 40 hour/week schedule and everything in my life has improved, health, life quality, quality time spent with my family, everything is better. Miraculously I earn more than before, weird, isn’t it?

A good setup goes a long way

I’ve been limited to a 13” screen to do my work on for ages and ages, well since July 2013 at least. The only person who did the limiting was myself. One of the things that contributed to the issue was working from home, and never having proper office space. DHH also praised working from his 11” MacBook Air on the go all the time. Although that is doable, and I first went with the 13” Air, then a 13” pro, there were certain times when something was missing.
Those certain times increased in rate and frequency when I started wearing different hats, working on everything from OPS, through backend Ruby on Rails, to front-end JavaScript development. Handling complex, multi-language projects is pretty tricky on a 13” screen. It’s not impossible, because I’ve been doing this for two years now. But if you can solve the pain you are feeling by buying a screen/mouse/keyboard combo, then there is no reason to suffer that pain.
Dissecting big problems into smaller chunks can also help a lot. But that also takes a lot of time, and you need to be able to look at the big picture once in a while. Although my eyes are still serving me well, there is no sense in destroying them on purpose. It’s also nice to be able to pass the Joel Test
So I faced another of those complex issues, where you have to look at the big picture while developing something. As it happens often, the lack of top level overview caused me to follow the wrong path a couple of times. Now, I don’t suggest impulse buying, and I investigated all the equipment beforehand. Luckily the computer shop near me had everything that I needed.
After a 10 minute setup, everything was up and running, I’m still getting used to my mechanical keyboard. It differs a lot from the MacBook keyboard I’ve been using for the last few years. But as I’m writing this article, I’m liking the feedback and the writing simplicity more and more. It kinda reminds me of the IBM model M keyboard that I had ages ago. I’d use it today, if my mother didn’t throw it away.
Having a 27” screen, alongside the 13” MacBook, is awesome. It takes me back to the time when I had to buy a new video card with my own cash. Then install it in my work computer on the previous job. Then I took an old 15” lcd from the company’s service room, putting it alongside my 17” screen. It was pure awesomeness back then, more or less.
Having an awesome chair also means a lot. I know people that praise their Aerons and Embodys and I don’t know what else is cool these days. I’ve sat in both of the mentioned chairs, and they are awesome. But I just won’t pay more money for a chair than I paid for my computer. Yes, you can buy a refurbished chair, but it’s still worth a hefty amount of cash. A few friends suggested that I buy Markus from IKEA, and I didn’t regret it at all. I can buy 10 of these chairs (maybe even more) for the price of one Aeron. And it’s an awesome super adjustable, comfortable chair.
What are your pain points with your computer setup? You have something that has been itching you for a long time. It’s easy to solve, and there is often an inexpensive solution to the problem. So go ahead and do it. Pull the trigger and buy the thing you need to flourish. You will feel the benefits immediately.

Your users are out to get you

How many times did you create a UI with a specific user flow in mind, and most of the time your users did something else? Did you ever experience users ignoring clear warnings and proceeding to do something dangerous to their data. Can we prevent this?

A user will always try to find shortcuts and model the app usage to what they seem fit. And it rarely happens that the end user uses the app in the exact way that you planned. If your app does allow users to skip any step in the flow, and do anything out of the boxed process you imagined, they will do it. Not all the time, but in your professional life you will encounter what I like to call creative users.

Now, I’m not saying that all users are ignorant, stupid, or criminal. But you must have that in mind when creating an application flow. Ideal user input that I can think of would be one button on an otherwise blank page. But even that imposes a couple of questions: How do we know who pressed the button? Did we state what the button does? Does the end user understand the language? If we do know who pressed the button, are they allowed to press it? What does the button do? Questions, questions…

There are also hackers, benevolent and malicious. And there are idiots that download hacking tools from various forums, playing stupid games. Now, I think that in a broader sense, benevolent hackers are doing great work for the community. You can’t plug all leaking holes in the thing you are building. It goes on a much greater scale when talking about libraries or web servers, ssl and encryption. While malicious hackers are after the money, they also expose holes that you learn how to plug. To be honest, no education is free, sometimes you pay less, sometimes more.

This is why having a good security practices works in the long term. Using a framework like Ruby on Rails solves a lot of that stuff for you. But don’t forget that you still have to have at least a grain of common sense. Even Rails allows you to shoot yourself in the foot, if you don’t follow the guidelines. Also don’t forget to upgrade to the latest security fix, or a maintained branch. Upgrading the frameworks or libraries to the supported versions might seem like a tedious thing to do, it’s the only smart option out there.

There are some drawbacks in using open source software. The number of solutions out there is huge. It’s hard to pick and choose the correct solution. I could suggest going with Ruby on Rails here, but that’s just my pick. Open source is also a great pool for learning new things. If you don’t seem to like one approach, nothing is forcing you not to create and publish your own solution. Just be sure it’s documented and tested, you created it because you weren’t satisfied with some other solution out there, right?

Back to (non-)malicious users again, that form you made to enter the email twice to verify it, it doesn’t work like that. I’ve experienced someone that used my own personal email to set up their Facebook account. My email wasn’t hacked (I hope), Facebook’s email verification sucks). I’ve since hijacked and archived the account, so no one can reuse my email to register again.

Now imagine a benevolent user, registering for your web service, and they enter a wrong email. I’ve worked with applications that have non computer savvy users, and that happens a lot. You make a typo, whatever, just while entering your email to register. Even my father who has been using a computer at work for the last 16 years or so still has troubles with typo’s. It’s not second nature to him, as it is to (most of the) computer professionals out there. And I believe you, the reader, are one of them.

Don’t judge a man until you have walked a mile in their shoes. Almost every culture has a variant of this proverb, and for a reason. The main premise is to do your best to see and feel what the other person is seeing, or feeling. Try to replicate their mindset while using your application. It’s easy creating applications for IT professionals. But when you realize that this is only a small percentage of the general population, the light bulb in your head might go off. Then you can think about a better solution to do the same once difficult task that only a few people understand.

Billionaire empires are created on simplifying complex stuff. Google simplified search and email. Apple simplified smartphones, and obtaining music before that (well at least legally). but there are lots of smaller examples, and you just have to look around to notice them. Complex UI’s have no place anywhere in the world, not even in airplanes or space shuttles. You need a lot of them, and sometimes you must have knobs and gouges somewhere where you wouldn’t like to have them. But if 99% of your users aren’t using them, maybe you can at least hide them from plain sight. You could even remove them, and get on with the fact that 1% of your users might leave. But the other 99% will have a much better experience.

Are you backup/restore procedures good enough?

So, my MacBook crashed yesterday. It didn’t really crash, just that it went black after logging in. Although I have a suspect, I won’t name it here because I don’t want to start a flame war or something. The issue is that the partition has became so corrupt that it couldn’t fix it with the Disk Utility. The only option was to do an rsync backup from the single user mode to an external USB drive, which took ages to do. Hint: to enter single user mode hold Cmd + S when powering on your MacBook. Strike one.

I do have a TimeMachine backup at home, but the laptop didn’t stay turned on long enough to backup properly. The last good backup was more than 2 months old. I found myself in a bad situation. The other thing that happened is that my brother’s laptop also stopped working the day before. His issue had something to do with the nVidia drivers on ubuntu. Good to see that nothing has changed since I last used linux and nVidia together 4 years ago. Being stupid as I am, I overwrote the macOS usb with the ubuntu image. All was fine with my MacBook, what could go wrong. Strike two.

Something happened during the restore procedure and managed to mess up the restore partition. The only option was going back to Mavericks that came installed on the MacBook when I bought it. I wasn’t planning on doing that. Strike three.

I managed to back up everything, deleted the system partition, and did a fresh install. After waiting for the macOS installer to download on my wife’s laptop, for at least 2 more hours. A day well spent, no person alive would say. But I did learn a few lessons though.

Have a backup (encrypted if you handle work/client/sensitive) stuff. It’s best to have at least 2 places with backed up data, using two different backing up solutions. TimeMachine and Carbon Copy Cloner work awesome together. You can always count on something going wrong.

Use cloud storage for the “important stuff”. Dropbox, Google Drive, iCloud, there are endless affordable solutions that all do the same thing.  They keep your valuables safe if a crisis happens. Have these things on your 2 backup locations as well, you can never know…

Have a fresh usb (or cd/dvd) installer of the OS you are currently using. I had this, 30 minutes before my computer crashed, I overwrote it, Murphy’s law in action. You got one over on me mr. Murphy, well played sir.

Having procedures like these won’t prevent situations like the one happened to me yesterday from happening. But they will surely reduce the stress caused by the situation itself. I couldn’t check if the drive was ok before backing it up and deleting partitions. Backup with rsync took 6 hours, maybe even more. If the MacBook was broken, it was at least a 4 to 5 days waiting period to get it serviced. I would be OK with this if it was holiday season, but it isn’t, and I have work to do. I could buy a new one, have it delivered the next day. I could even drive to the store and pick it up myself, but why buy a new one if the old one isn’t broken. What to restore on that machine, I have unreleased stuff that isn’t in the cloud yet? Stress levels were pretty high.

In the ideal case, I’d have a backup from the day/night before and it would take me 10 minutes to decide it’s worth killing the machine and starting fresh. The os installs in 15-20 minutes, I can restore the apps/settings from the backup, or even do a full TimeMachine restore. With an external USB 3.0 drive, it would be quite fast. I could have done some productive work yesterday. Instead I spent the day staring into rsync output, hoping it will finish soon. I like the experience though, because I’ve became sloppy, and this is a fair warning to what could have happened if the SSD decided to stop working. I was lucky that I only lost a day of my life, but I learned a valuable lesson. I hope that you can learn from my mistake.

Doing new things is hard, choose your hard

In my last post I touched on the topic of quitting, and how easy it is to take the easy path instead of the hard one and quit. Most of us quit all the time, big and small things alike. When things get a little tough, it’s really easy to drop back to a place where you feel comfortable. And while we often quit, we rarely understand the consequences of that act before it’s too late.

When was the last time that you were assigned with something you’ve never done before and it seemed easy and straightforward? If I had to guess, the answer is never. New things are hard to us for a reason, we didn’t create any patterns around the process yet. Even if it’s something that you’ve enjoyed doing in the past, it takes you time to get accustomed to it in a different environment.

Maybe this is a filter of some kind, because people who persist in their efforts are the ones you hear or read about. We all have our struggles in life, the only thing that differs is will you give up or continue fighting, will you take the easy road, or the hard road. Just bear in mind that the easy road can and probably will be harder for you in the long run.

People have different learning patterns, and different backgrounds. While new associations in our mind are easy to create, it sometimes takes time to link everything together, or to figure it out. That process is hard. If you ever tried to learn a foreign language you’ve encountered it, along another issue, you need to use the language to learn it.

The best way that I’ve experienced is using what you’ve learned from day one, it will be hard for a while, but much easier in the long run. Yes, you will go full Tarzan mode with constructs that translate to “I want go food” or something similarly funny.
The trick is not to be afraid or ashamed while you are learning something new, otherwise it wouldn’t be hard for you to do it. If you are surrounded with the right kind of people, they will encourage you and help you, even dedicate significant amounts of time into helping you, because that is something they also care about.

Same thing goes with learning new computer languages, or programming paradigms. Yes it’s hard to learn Object-Oriented programming, it is also hard to learn Functional programming. While I’m on the subject, it’s pretty hard to learn testing, and that is just the high level stuff. Everyone one of us has been an apprentice at one point or another.

Sometimes I am still an apprentice in some new technology that I’m interested in. You will always have new stuff to learn, it will (probably) be hard, maybe you even won’t succeed, but are you willing to immediately give up the benefits you could reap for your whole lifetime just because you need to suffer for a day, or a week? I’m not, when something gets too easy for me, I just have to find something new that will push me even harder in the direction I’m moving to. It’s pretty easy to figure out that most of the things that you appreciate in your life are hard. Raising children is hard, running a business is hard, competing in sports is hard, sometimes even breathing seems hard. Do you really want to spend your whole life as a couch potato, watching TV and not achieving what you might if you just put in some effort?

I’ll end this with a nice quote from a three-time Tour de France winner Greg LeMond: “It never gets easier, you just go faster.”

It's really easy to quit

I remember when I was in my late teens, although I rode on the bicycle around a lot, I never did anything longer than a few kilometres in one go. I had an old steel mountain bicycle, heavy as hell, but it was enough for me.

Once I decided to visit a friend who lived about 25km away, and decided to bike there. It was one of the worst experiences in my life. I barely managed to do it, having cramped muscles for days after that, also I went back home by train, bicycle with me.

Nowadays, after 15+ years I can successfully ride for 100 and even more kilometres, probably using less energy than ever before. I admit that I have better bike(s) now, but that is not the point. 15 years ago I just gave up on the spot, as soon as it got hard. Quitting was easy, except for the next couple of days when I could barely walk, but the act of quitting seemed pretty liberating. You just run away and don’t look back.

A few months ago I went on a ride alone, and after 2 pretty hard rides in the two days preceding the current ride, my legs were pretty empty in the start. And I had 4 climbs on the route. I almost gave up after the first climb, but then something hit me. The pain you are feeling now, just means that when you go out tomorrow, or the next day, you will be even stronger than you are today.

By putting constant effort, especially when you don’t feel like it, you will gradually improve. I like to measure my cycling performance a lot, because if you can measure something, you can improve it. I’m far from being a pro, and I’m pretty far from competitive racing, excluding one with myself. The bike pulled me out of a really bad place I had put myself into. I’ve lost 40 kilo over 3 years on the bike, and now I’m feeling better than ever.

I’m using a cycling analogy here, because it’s the easiest thing that comes to mind here. But the real story I want to tell you is about yourself. You are the one that quits when it gets hard, I know it, I was the same, quitting when things get tough. Requiring constant and immediate feedback is something people cherish a lot, but the things that give you immediate feedback are mostly bad for you.

What I’m trying to point out here is that you are the only person responsible for your own destiny. If you are willing to go through life as a quitter, giving up as soon as it gets a bit harder than usual, you will become weaker and weaker. By not challenging yourself with new things every day you slowly degrade.

There is a pretty common saying that businesses which are not growing are falling apart. You could be stagnating, but given that everyone else around you is growing, you might as well be in the red, it is mostly the same. And this relates to people really well. Just think about your parents, or grandparents. Some of them know how to use a computer, some are pretty proficient with it, and some can’t even use a microwave.

Back to you, if you are a programmer, there was a time in your life when the only thing you knew how to code was ‘Hello World!’ in some language that you don’t use anymore. Why did you continue through the hardships of learning other languages, patterns, algorithms, just to call it quits today?

I hopefully have a couple of decades left to do something productive, can’t even imagine the language I’ll maybe be writing code in before I choose to retire. I might not even be writing code then, but I’m not afraid of it at all. Life is a constant change, and by accepting it, and going with it, you will find yourself being a better person than you were before.

One person told me a pretty resonating thing, and it stuck in my head. If I didn't challenge myself to do hard things, I would still be stuck doing a shitty job that I did 3 years ago. And it’s true for me too, on different levels. I now have a really great job, more energy and a lot more chance to hopefully get to see and play with my grandchildren in 20+ years. And I don’t really care about what will happen tomorrow, because I know I will deal with it.


Exercising is really good for you, and you must start immediately if you want to play with your grand children, even great-grandchildren if you are really lucky. I know people who can’t even go out and play with their own children because they just called it quits on their own health. It’s really sad, but I don’t think they will even live to see their grandchildren. Tech jobs are pretty sedentary ones, and I know how easy it is to stuff yourself with fast food, while working 12+ hour days, getting bigger and bigger. If you are in this situation and don’t know where to start, there is a great book by Joe Kutner called The Healthy Programmer. If you need more help don’t be afraid to contact me. I’ll be glad to help you get on your way to feeling and doing better.

Don't (only) focus on the code

Every developer aspires to create great things, but often the most important issue is not just the quality of your code, but many other and obscure things that are setting you back from achieving your and your company’s goals.

You should write good, well tested code, which doesn’t have to be perfect, but merely good enough. I know that some of the purists will get mad but that is often the case. As the saying goes, Perfect is the enemy of good enough. I won’t go into the quality of the code anymore, because I believe you, as most of the programmers do, write good enough code. What you should focus on is something completely different.

There are three things that you can do while working for a company or consulting for a client:

  • Create value
  • Reduce expenses
  • Both of the above

Ultimately I want you to always think of the ROI (Return On Investment), for either your employer, your client, or yourself in the end. If you steer away from that focal point, and start procrastinating on delivering the product, because the code, design, or copy is not perfect, you will never ship it. Also, if you are not embarrassed by your first release, you have shipped too late.

Now, think long and hard, what situations call for further improving the quality of your code to stick them in the three categories mentioned above? Testing and refactoring bad code will improve future maintainability, which reduces expenses in the long run. Optimising for performance and making the application faster can bring you more clients and earn more money. Optimising workflows will cut the time needed for the end-user to finish a unit of work faster, which reduces expenses per unit of work, allowing them to do more in the same amount of time, or to work less.

Automation is a nice thing to have, but unnecessary in the beginning. If the product that you are creating succeeds, and you start spending a lot of time on processes that should be automated, please automate them, and delegate the execution to someone else. But don’t do it before it really starts to hurt, because you are wasting your (and the company’s) precious time.

Understanding how and why the software does what it does should be the main thing for you to learn about. I agree that you can be some level III programmer in an enterprise behemoth, really detached from the process, being fed with your daily or weekly tasks through some project planning tool and not really knowing how the sausage is made. Maybe you are one of the Dark Matter Programmers, and aren’t really ambitious to move up, and that is also OK. I know people that are in the same situation as you are, happy with the work they are doing. Although I consider this approach highly insecure and uncertain for the long run, it is practical for the present, for them.

If you are focusing on the process, and eliminating the obstacles to reach one of the three points mentioned above (create value, cut expenses, both of them), then your software will be better in the long run. In that process you stop being just a programmer that is easily replaceable, and start being a true business consultant, with a unique set of skills.

As an example, there is a process that each end user has to do to make one widget. It includes going through 10 different screens, and entering a dozen parameters on each screen to produce the widget. Creating any type of widget generally takes 10 minutes Although the company makes different types of widgets, let’s say that one widget accounts for 80% of the sales, and all others for only 20%. Optimising the code in this situation does nothing, because the code has to produce a variety of widgets, and unless it’s really messed up, you should leave it alone.

Optimising the process on the other hand is something completely different. Especially if we have a situation like I mentioned above. I really love the Pareto principle, and try to use it all the time, applying it to any situation will allow you to focus on the stuff that really maters and ignore/drop the stuff that doesn’t.

How do we apply it to the above example? Let’s call the widget that accounts for 80% of the sales The Golden Goose. All widgets have around 100 properties you can set while creating them, but 95 of them are the same for each Golden Goose. So why bother entering and checking each one for a process that happens 80% of the time. Optimising the process from 10 screens and 100 parameters that takes at least 10 minutes and allows for a lot of human error, to one screen and 5 parameters, which reduces the widget preparation time to only one minute will drastically increase the user productivity, allow them to push out more widgets in the same time.

By focusing on the business and not only on the task at hand, you will stand out among your peers. There is no difference whether you are an employee, a freelancer or a consultant, your customers will generally have more respect for someone who looks at the bigger picture, and speaks their language. You can do yourself a big favour and read a couple of business books. It is a very big chance that you work for one, so why not invest a couple of hours in understanding how businesses work. It is a very small chance that those hours are spent in vain. If you don’t know there to start, The Personal MBA by Josh Kaufman is really great, and I can’t recommend it more.

The LinkedIn experiment

If you are an engineer you probably don’t see much use from LinkedIn as a service. It is full of recruiters, who can be very annoying from time to time. You can choose to link people you have worked with, went to school with, or know from one source or another. Aside from this fact, I didn’t see that much use in LinkedIn. So I decided to run a small experiment. No, I won’t give them access to my email or something stupid like that, but I’ll do my best to use the site as it was intended to.

I’m not really hoping to gain anything from it, aside from maybe a new connection or two. I know I’ll get spammed like there is no tomorrow, and that was one of the reasons I killed my profile a couple of years ago. But this time I mean business.

I’ll do my best to post updates, link interesting articles, fill my profile with everything I can, and even leave a review or two. I’ve already started doing some of those things, and I’ll follow the plan at least till fall.

As I’ve previously mentioned, I don’t want anything. I’m not looking forward to getting spammed by recruiters, and I probably won’t be looking for new projects soon. I just want to see what can be done with it. I’m always open to finding new acquaintances and similar minded people. I was also considering joining (or starting) a mastermind group, and maybe LinkedIn can provide some help with that.

If I don’t get anything out of this small experiment, and I sincerely doubt that I won’t, I believe it will be a small amount of time well spent. I’ll surely write a post about my results in a couple of months.

Understanding the Ember run loop

All of the Ember.js internal code, and most of the stuff you write while creating an Ember.js app runs with the help of the run loop. It is used to batch, order and reorder jobs in a way that is optimised for efficiency. I didn’t notice it’s existence before I ran into problems with the JavaScript setTimeout function callbacks and when manually running async calls to the API.

How Ember run loop works

If you’ve read any of the productivity books out there, they all state that batching similar jobs is the key to success. Ember run loop works in a similar way. By running same or similar jobs at the same time, the browser doesn’t have to skip around from task to task, which eases the burden on it, and if you change the same property a couple of times in the same loop cycle, it will only have to process the last change.

Jobs or tasks are scheduled into different queues, and the queues are processed by priority until they are empty.


Ember run loop consists of six queues
// => ["sync", "actions", "routerTransitions", "render", "afterRender", "destroy"]

Each one of these queues is responsible for some jobs batch that runs inside of it.

  • sync contains the binding synchronisation
  • actions is the general work queue, and the one that generally handles promises.
  • routerTranisitions contains transition jobs in the router
  • render contains the jobs that are associated with rendering the page and updating the DOM
  • afterRender runs after the DOM is complete, after all the render jobs have been executed. This is the perfect place if you want to update the DOM after it has been rendered.
  • destroy is responsible for destroying everything other objects or jobs have scheduled to destroy.


Ember run loop is really important when running tests in Ember. Ember raises errors in testing mode when we try to schedule work without the run loop.

When should you use the run loop

Strictly speaking, all non Ember api code should be wrapped inside an Ember run loop. That includes:

  • AJAX callbacks
  • DOM updates and event callbacks
  • Websocket callbacks
  • setTimeout and setInterval callbacks
  • postMessage and messageChannel event handlers

Be sure to wrap the callback body in the ember run loop and not the whole invocation. For example:

var controller = this;
socket.on('channel', function (data) {, function() {
    this.set(‘message’, data.message);

This fires an Ember run loop after the callback is executed, and the callback code will be executed at exactly the right moment.