My Journey Deploying a Django + Supabase application to Vercel.

Photo by Matt Duncan on Unsplash

My Journey Deploying a Django + Supabase application to Vercel.


1. INTRODUCTION

Hey, there. In this article, I'll be talking about my experience in deploying a Django app using Supabase as a Database to Vercel. For the technical know-how, please refer to this article on kowe.io.

It's not a common thing to deploy server-side projects to Vercel, and so when I did that, I knew I had to share my experience with you as I navigated the process. One of the most significant decisions I had to make was where and how to host the application and its database. After extensive research and a bit of trial and error, I decided to go with Vercel for hosting and Supabase for the database šŸš€.

2. SETTING UP PROJECT

Now, letā€™s dive into the nitty-grittyšŸ±ā€šŸ. My projectā€™s architecture relies heavily on Djangoā€™s flexibility, the robust ecosystem of packages, and the wealth of resources in its documentation. Django is like an old friend to me, offering a structured approach to application development while still allowing me to handle complex data relationships.

For the database, I opted for Supabase, a versatile and developer-friendly platform that simplifies database management and provides real-time capabilities. The beauty of it is how seamlessly it integrates with my Django application. It made development and testing feel like a breezešŸ˜‰āœØ.

3. WORKING WITH SUPABASE

Integrating my Django app with Supabase was smoother than I expected, thanks to their Supabase database URL that includes everything you need to connect to your Supabase database. Itā€™s that straightforward! itā€™s just like plug-and-play. This cloud database platform not only simplified database management but also enhanced my Django applicationā€™s capabilities.

Supabaseā€™s strength lies in its user-friendly interface. Setting up your database and managing it becomes a breeze. Whether you need to design a new schema, migrate data, or make real-time changes to your database structure, the Supabase dashboard is your go-to toolšŸ¤ž.

4. DEPLOYMENT ON VERCEL

Deploying my Django application on Vercel wasnā€™t very straightforward(Iā€™ll dive deeper into that in the next section). For those that don't know Vercelā€™s platform is primarily designed for hosting and deploying frontend and serverless applications. While itā€™s exceptionally well-suited for serving frontend code, static assets, and serverless functions, it doesnā€™t provide native support for hosting traditional server-side applications, including those built with server-side frameworks like Django.šŸ˜ž

If you have a server-side application, consider other hosting providers or cloud platforms better suited to manage server-side code. However, if your application is still small and in the testing phase, then deployment on Vercel can still work. šŸ‘

5. CHALLENGES AND LESSONS LEARNED

Of course, no journey is complete without its fair share of challengesšŸ˜…. I encountered a significant challenge during the deployment of my application on Vercel. Upon the completion of the deployment process, the application presented a 504 Gateway Timeout error, signifying that the request from the wsgi.py file to the web server had timed outšŸ¤¦ā€ā™‚ļø. This issue was unexpected, particularly because I had previously deployed the same application to the Railway without encountering this error.

In my quest to understand the root cause, I conducted research on Vercelā€™s platform. It came to my attention that Vercelā€™s serverless functions, which require a request from the wsgi.py, have a default time limit of 10 seconds for processing requests, especially applicable to hobby projects.

Given the complexity of my Django project, which consisted of four(4) separate apps, it exceeded the specified time limit to send a request, ultimately resulting in the 504 Gateway Timeout error. To increase the timeout for serverless functions on Vercel, this typically requires an upgrade to a paid plan which was a major deal breaker for me.šŸ’”

In the quest to resolve the 504 Gateway Timeout error on Vercel, I found myself at a crossroadsšŸ¤·ā€ā™€ļø. The existing Django project, with its intricate structure and multiple apps, had exceeded Vercelā€™s serverless function timeout of 10 seconds. While the idea of breaking down the project into smaller, more manageable components had crossed my mind, I faced the reality that significant refactoring would be requiredšŸ˜«.

Refactoring, while a valid solution, would mean a substantial overhaul of the existing codebase, restructuring, and optimizing it to fit within Vercelā€™s constraints. It would have been a time-consuming and resource-intensive process, and there was no guarantee of success without extensive testing and fine-tuning.

In light of these considerationsšŸ’”, I began to explore an alternative path. It dawned on me that I could create an entirely new Django project specifically tailored to align with Vercelā€™s serverless function limitations. This fresh project would be designed from the ground up to operate seamlessly within the 10-second time frame, without the need for extensive refactoring and adjustments.

The decision to opt for a new project had its advantages. It provided a clean slate, allowing me to architect the application with Vercelā€™s constraints in mind from the outset. This approach promised a quicker resolution to the 504 error, as well as a more efficient development process without the need to unravel and rebuild the existing codebase.

6. BENEFITS AND FINAL THOUGHTS

The benefits of deploying my Django app on Vercel with Supabase were well worth the journey. Though the deployment process was not as efficient as I had hoped, it taught me the importance of the adaptability of applications to meet the requirements of hosting platforms.

7. CONCLUSION

My journey deploying a Django application on Vercel with Supabase was a rewarding experience, and I wanted to share it with you. I hope that my story provides guidance and inspiration for others considering similar deployment options. When you combine the power of Django with the hosting capabilities of Vercel and the versatility of Supabase, the possibilities for web application development become boundless.

8. TIPS AND TAKEAWAYS

  • Consider Django & Supabase for a versatile and scalable application stack.

  • Opt to use Vercel for small projects that donā€™t require much scalability.

  • Before choosing a hosting platform learn its strengths and limitations.

9. REFERENCES AND RESOURCES

Ā