Technical Interview for Ruby on Rails
Technical Interview Outline
- Warm up questions
- Technical knowledge questions
Warm Up Questions
The warm up questions are designed to help the candidate get comfortable with the interview.
Question 1
What is Ruby on Rails, and how does it differ from other web development frameworks? Can you give us some of its benefits and drawbacks?
Purpose: Understand if the candidate knows some of the pros/cons of Ruby on Rails.
Question 2
If I have a resources :users
declaration in my config/routes.rb
file, and I
POST to /users
, what's the controller and action that handles the request?
Purpose: Understand if the candidate know the basics of RESTful routes in Rails
Question 3
Describe the process and components involved when a request comes into the Rails stack and a response is sent back to the client.
Purpose: Understand if the candidate understands what happens behind doors when a request to the server is made.
Technical knowledge questions
Gathering Requirements
Let's say you're going to build an application similar to Reddit. Reddit has multiple forums called subreddits, where people discuss a specific topic. For example, there might be a subreddit for Ruby on Rails, another for dogs, and yet another for philosophy. Within a subreddit, people can post their thoughts on a particular topic. Each post can contain text, links, pictures, and videos. You can edit your own posts, but you are not allowed to edit content posted by other users on the site. However, administrators have the authority to edit content, regardless of who posted it. Any user can leave a comment on a post or on another comment (thread). Finally, people can upvote posts and comments from other users.
You're part of a team of two developers and one designer who are going to develop this site from scratch.
Note: Read the requirements again. Ask the interviewee if they have any questions about the requirements.
How would you model this reality in Ruby on Rails? Ask for a high-level overview without going into much detail so it doesn't take much time.
Purpose: Understand how they gather requirements. Correct understanding of models and dependencies between them.
The client is hoping to launch two weeks from today with all of the features described above. What approach would you take?
Purpose: Assess the candidate's ability to critically evaluate project requirements and deadlines. Can they effectively communicate and negotiate the project scope and timeline? Are they open to exploring alternative strategies, such as extending the deadline, prioritizing features, or expanding the team size?
Admin users
Given that:
- Any user can sign up for the site and create a post
- Any user can view any post on the site
- Users can also edit their own post
- Normal users can't edit posts created by other users
- Admin users can edit any post in the system
How would you implement this permission scheme?
Purpose: What they would do at the controller/model level?
See if they overcomplicate things with roles, or something created from scratch.
Are they using something like cancancan
or pundit
?
Comments
Given that:
- Comments can be added to either posts or other comments
How would you implement the comments system in a way that ensures minimal code duplication?
Purpose: see if they can handle relations to more than one model. The most obvious solution is Single Table Inheritance (STI) or a polymorphic association. Make sure they discuss models, views, and controllers.
Feed
We now want to introduce a feed in the home page, where we will show an activity stream of what every user did on the platform. If they posted something on a subreddit, commented in a post or a thread, it will be displayed there.
The site is running well, but there have been minor bugs and you're concerned that performance may become an issue if the user base expands.
What are some questions you would ask the client about this new requirement?
Purpose: see if they attempt to determine the motivation behind the feature, reduce the scope of the feature, or clarify where it lays in terms of prioritization. It doesn't make much sense to display every comment in the feed, so they might raise a flag about that feature.
Assuming you were going to build this feature, how would you implement the activity stream?
Purpose: see how they can handle cross-cutting concerns and combining several sources of potentially disparate data. If they propose a NoSQL solution, encourage them to find a way to implement it using SQL. Check to see if they can devise a solution that doesn't over-fetch data and avoids performing sorting operations in Ruby.
Debugging Performance
Until now, the site has been working well. However, after deploying the feed and a few other features, every page on the site is slow to respond. Some requests even time out before the server finishes sending a response.
What would you do first to try and locate the problem?
Purpose: Ensure that their problem-solving methodology begins with figuring out the exact problem before proposing a suitable solution. For instance, scanning through New Relic or logs for slow actions or queries is a logical step. However, initiating a caching layer without first identifying the issue is not. They could recommend looking for N+1 queries, utilizing tools like the Bullet gem, profiling the application, monitoring CPU/RAM usage on platforms like Heroku or AWS, etc.
JavaScript
The client has suggested the idea of allowing users to "upvote" content or comments. Ideally, interacting with the content will happen seamlessly without reloading the current page. How would you implement these interactions?
Purpose: see how they approach interactive features in a web application. Does JavaScript play a role? Does a client-side tool like React make sense? Are they aware of Turbo?
Removing Features
The feed feature has been active for some time now, but it's not widely used by users. Considering its significant performance impact, the client has decided to remove it.
What would you do with the code that powers the activity feed?
Purpose: see how they handle obsolete code. Do they delete it entirely? Comment it out? Use a feature flag? Revert the commits that introduced it?
Testing
We want to start adding tests to the platform.
What mix would you recommend for high level tests (feature, system) vs low level tests (unit, model)?
What do you do about duplication in unit tests?
What's one common cause of slow test suites?
What's one common cause for tests which fail intermittently?
Purpose: we want to understand if they see value in having a good test suite. Do they understand how to use factories, before hooks, let statements, and shared examples to reduce duplication in unit tests? Do they know that the common cuases of slow test suites are excesive database interaction? What about using mocks to speed things up? Do they know about flaky tests? Some common causes for flaky tests are race conditions and test data that is non-deterministic (for example, a test that depends on the order of the records returned from database).
Wrapping Up
At the end of the interview, we give people another chance to ask questions. Some people ask about the answers they gave to other questions, or what your answer might be to a specific question.
If you have any feedback regarding their answers, feel free to share it.
After answering any questions, make sure to thank them for their time and let them know that we'll be back in touch shortly.