How to Actually Implement a Feature in Your App
An overview of how to take a feature from idea to implementation, with actionable steps for what to do and a real-world example.
Listen to Article
How to Actually Implement a Feature in Your App
Recently, I released a feature on my Next.js website that allows users to purchase courses using a Stripe checkout system. I thought I'd write a piece to actually explain my approach to building a feature like this so that others can get a better idea of what to do in their own apps.
Forming a user requirement
The first step is to actually come up with an idea for a feature. When working on a new project, I find that the more time and effort I spend working on the project, the more ideas I tend to have.
This is because, after you've spent some time working on the project, your mind is then able to look back on your existing pile of work and use it as data for where to go next. You are able to have intuitions about the work that you have already done and do convergent/divergent thinking on it. Whereas when you have no existing work at the start of a project, it can sometimes feel like trying to draw blood from a stone, trying to get something from nothing. Or in other words, once you get the ball rolling, it becomes easier.
If you have absolutely no idea of what features to add to your program or are starting with nothing, its a good idea to take a look at what other people have already done and go from there. When building the blog for this website, I spent a lot of time looking at existing sites like dev.to to get a better idea of what features blogs normally have. You should be doing the same for your product.
When looking at existing products that are popular, chances are they have already implemented lots of solutions that are optimal. The features on and structure of popular websites are normally decades worth of iteration and optimisation so you might as well pinch them. There's no need to re-invent the wheel. It isn't stealing. This is just how good ideas become industry standards.
In the case of my course purchasing feature, the desired feature can be summed up succinctly in this sentence:
- There needs to be a feature that allows users to purchase courses.
This is the idea I came up with for the feature, but it can also be thought of as a user requirement for the website. Coming up with the user requirement is step 2.
Breaking down the problem
The user requirement can then be broken down into a simple flow chart:
This is a high level overview of what the feature needs to do. It can also be thought of in more simple terms as:
- The user buys a course.
- The user then gets the course.
The feature is a simple exchange of inputs and outputs. Which is the shape of pretty much all features in software. Creating our flow chart is step 3. Normally I do not physically create a flow chart in the sense of going into a software program and drawing it out, but I am able to break the problem down into actionable steps in my head.
Whatever method works for you, you should go with. If drawing the flow chart out and taking some time to break down the problem on paper helps, then you should do that. If you are able to work it out mentally then that is fine too.
Satisfying the flow chart
The goal is now to add code to your app that satisfies the flow chart of your feature. This is step 4. If the code that you add satisfies the flow chart, then it satisfies the user requirement that we stated earlier and our feature will have been implemented. Another way of putting it would be that this is now a true statement:
- Our website has a feature that allows users to purchase courses.
At this stage, the objective is simply to satisfy each step of the flow chart. How you are satisfying each step isn't important right now. The only thing that matters is that each step of the flow chart is being satisfied.
For each step of the flow chart of your feature, there will be billions of different permutations of how that step could be implemented. But right now, we aren't interested in how each step is being satisfied, our focus is just that they are being satisfied in some way.
This is because our goal is to implement the feature (by satisfying the flowchart and thus satisfying the user requirement). Not to get stuck perfecting the implementation to step 1 of our flowchart - while the clock ticks down for the delivery date of that feature.
This is how you actually meet deadlines and don't overshoot them. The focus simply needs to be on satisfying requirements, not designing perfect solutions for them for the time being.
Iterating on your solution
Of course, at this stage, while the feature will have been implemented, it will most likely not be the optimal solution. Our goal now should be to:
- Handle edge cases.
- Resolve bottlenecks.
You can handle edge cases simply by testing your solution against what an average person would expect it to do vs what it does. The analogy that I always come to is of patching up a road. What we discussed in the previous section was us laying out the broad structure of the road to our goal. We now have a clear route laid out but we then need to go back and patch up potholes and defects in the road that we may have made while blazing the trail forward, otherwise somebody might fall in.
Bottlenecks occur when there are unnecessary steps between the user and a desired outcome. Or that there are too many inputs for a desired output. The user has to give a lot to get only little from your program. If your product suffers from too much of this it will fail. The juice will not be worth the squeeze.
Excess steps:
Excess inputs:
Eliminating these unnecessary steps and reducing the number of inputs for a desired output improves the efficacy of your feature.
Iterating on a feature is an ongoing process. As a system matures it eventually becomes more robust, functional and effective. The key to ensuring that your system improves is continuous real-world feedback. A variety of different users need to interact with your feature from a variety of different devices. This gives broad feedback that you can then improve the system on. You also need to be using your feature yourself so that you can spot edge cases and bottlenecks on your own.
Recap
To recap, our steps were:
- Define a user requirement.
- Break the problem down into a broad flowchart.
- Implement a solution that satisfies the flowchart.
- Iterate on the solution.
How I satisfied each step when making my purchase course feature
We've already been over how I met steps 1 and 2. As for step 3 (the implementation), I started by adding a new component - PurchaseSeriesBar - to my existing course page.
The existing course page fetches information about a course (title, description, cover image and metrics about the course) and the articles within that particular course from my Convex backend. This information is then displayed in various cards and sidebars.
Complete PurchaseSeriesBar component
This component contains the purchase button, which is conditionally rendered based on whether the user has already purchased the course or not. It also contains a loading state that is triggered when a user is being redirected to the stripe checkout flow.
The onClick handler for the button calls the handlePurchase function which checks if the user is correctly authenticated and, if so, calls the startCheckout function to begin the stripe checkout flow.
startCheckout function
As the name suggests startCheckout kicks off our Stripe checkout flow. It does this by awaiting createCheckout:
Which is a hook that lets us trigger Convex actions. The particular action that we are triggering is createCheckoutSession. I've obscured a few details here to protect some of my business logic but the general pattern is the same:
In our application, we now get a Stripe checkout flow when the user clicks purchase!
In our Stripe dashboard, we are then listening for successful purchase events and trigger a webhook when a user makes a purchase so that a table is updated in Convex to give the user their course. We wont show you this bit though, as we want to keep our business logic private!
As you can see however, our frontend is updated nicely to reflect the users newly purchased course.
The flowchart is satisfied
If we go back to our original flowchart, we can see that this implementation does indeed satisfy each step.
This means that essentially the feature has been successfully built. Of course, this system relies on existing systems that are already present in the website (the course viewing page, the profiles page, the "My Library" page, Stripe onboarding, etc). Building those systems just comes down to the same approach, however:
- Come up with the idea for the feature.
- Break it down into broad steps.
- Create a solution that satisfies each step.
- Iterate on the solution.
The last point is quite important here. Although we have built a feature that technically satisfies the requirement, we need to iterate. This is because at this stage we have not handled edge cases and addressed bottlenecks.
While the solution does exist at this point, it is very brittle. Let's look at some examples of how it can be made more robust.
Edge case example
One example of an edge case is that users might try to purchase a course before they are logged in. If a user is not logged in, then we can't add the course to their library as we wont know what user to give it to.
When I first made the checkout system, I did include the rudimentary check in handlePurchase:
While this will prevent users from purchasing a course who aren't properly authenticated, of course, it provides no feedback to the user about what went wrong and where to go from here.
To handle this properly, I created a new component, SignInDialog:
This prompts the user to sign in or sign up if they click purchase and aren't yet authenticated. Effectively handling that edge case.
Bottleneck example
When working on the edge case solution I mentioned in the previous section, I had to make a choice about how I would actually prompt the user to log in. While my final choice was to settle on the option where I place the sign in/up forms in a shadcn Dialog component, there were other options too.
My first idea was to give the purchase button similar functionality to how I handle unauthenticated users trying to click the My Feed option in the blog:
Which is to say, I use a toast to display an error message and a button to sign in.
While this is fine for a users feed, when purchasing courses I think it causes too much friction. A user would have to see a small 'Sign In' button at the bottom of the page which is only visible for a few seconds, click it, which then navigates to a different page entirely, so that they can sign in.
This system is too inefficient. If we consider our previous examples:
- There are too many unnecessary steps (clicking an extra button to trigger a sign in flow, navigating to a different page entirely, etc).
- There are too many unnecessary inputs for the desired output (too many clicks just to sign in/up before purchasing a course).
The more effort that the user has to put in to purchase the course, the lower the likely hood that they will actually go through with the purchase. They might determine that the juice isn't worth the squeeze.
Using a sign in/up Dialog prevents this, however, as it gets the user signed in/up as quickly as possible without any extra clicks or navigation.
How the feature evolves going forward
This is still a new feature on the platform. Therefore, it will likely continue to go through iterations and updates in the future to further reduce bottlenecks, cover edge cases and interact with other systems that I will build into the platform. As the feature is deployed live on the platform, the evolution of the feature will be in response to real users actually interacting with it. By working this way, we get real-life feedback about how people are actually using the feature so that our updates are grounded in reality instead of being detached from what users actually want out of it. When building features, you typically don't want to speculate on what users want out of your platform, but rather respond to objective, measurable data and metrics.
We can measure how long users stay on the page, how many click purchase but then don't end up actually completing the purchase flow, etc. This gives us great insight into what we can actually do to increase purchases.
What we didn't cover
Checkout systems can be and typically are more complex than what was covered here. If you go to any popular e-commerce site, they will have a basket system, transaction history, refunds, customer support, etc.
These might be good features to implement on my site next, and could be the next stage of evolution for this feature. It's important to be able to identify individual features though. When you go to an e-commerce site and see that you can buy things, its easy to think that all the payment features are a single system built in to the site that would take ages for one person to make. In other words, its difficult to distinguish between individual systems that can stand on their own when they are interacting closely with other systems.
How we use the checkout system we built
We just finished building a course that you can purchase for the low price of £6.99. This course contains 4 articles and about 40 minutes of reading material, going into depth on how to get a job as a software developer. It's great for juniors trying to get into the industry but also contains lots of helpful advice for anyone at any stage of their career. If you are interested, pick it up and give it a read!
How to Get a Job as a Software Developer
Stay Connected
Get notified whenever we publish new articles, insights, guides and product updates.