How We Built a Scalable Web Application Using Python and Django: Lessons from Food Delivery Platforms Like Deliveroo


shape
shape
shape
shape
shape
shape
shape
shape
image

Introduction

With the rise of AI, businesses now have the ability to automate repetitive tasks, freeing up their teams to focus on higher-value work. One area where AI can be particularly impactful is customer support. Large companies receive hundreds, sometimes thousands, of support requests daily. Sorting and categorizing these tickets manually is time-consuming and prone to errors.

Our team recently implemented a machine learning model using Python to automate the classification of customer support tickets. This solution allowed the client to reduce response times, prioritize urgent tickets, and ultimately improve customer satisfaction. In this post, we’ll walk you through our approach, the technical challenges we faced, and the results of the project.

Why Automate Customer Support Ticket Classification?

In any customer-centric business, providing timely responses to support queries is crucial for maintaining satisfaction and loyalty. However, as a company scales, managing the volume of support requests manually becomes inefficient. Automating ticket classification offers several benefits:

  • Faster Response Times: Automated classification enables the system to route tickets to the correct department or priority level instantly.
  • Consistency: Machine learning models can apply a consistent categorization logic, minimizing human errors.
  • Improved Efficiency: Automation reduces the workload for human agents, allowing them to focus on resolving issues rather than sorting tickets.

This use case is especially relevant for companies like Deliveroo or similar platforms, where the volume of support queries can spike unexpectedly (e.g., during meal delivery times), requiring efficient triage and handling.

Solution Overview: How We Built the Ticket Classification System

Our AI-powered ticket classification system was designed to read incoming support messages, categorize them, and prioritize them for the appropriate department or team member. Here’s a high-level overview of the solution we implemented:

  1. Data Collection and Preprocessing: We collected historical customer support tickets from the client, which included labeled categories such as "Order Issue," "Payment Problem," "Delivery Delay," and "Account Assistance."
    • We used Python libraries like Pandas to clean and preprocess the data.
    • For text processing, we applied techniques such as tokenization, removing stop words, and lemmatization to prepare the data for machine learning.
  2. Feature Engineering and Text Vectorization: To convert the text data into a format that a machine learning model can understand, we used:
    • TF-IDF (Term Frequency-Inverse Document Frequency) for vectorizing the text data, capturing the importance of words within each ticket.
    • Word embeddings with libraries like Gensim and spaCy for enhanced semantic understanding, which can be especially useful for understanding the context of customer complaints.
  3. Model Selection: We tested several machine learning algorithms to find the best performer for this task:
    • We used Logistic Regression and Support Vector Machine (SVM) as baseline models for comparison.
    • Ensemble models like Random Forest and XGBoost were tested to see if they improved accuracy.
    • Ultimately, we chose a Multinomial Naive Bayes model for its high accuracy and low computational cost, ideal for real-time classification in a high-volume setting.
  4. Training and Tuning the Model: We split the data into training and test sets, using cross-validation to tune hyperparameters for optimal performance. This ensured that the model could generalize well to unseen data.
  5. Deployment: The model was deployed as a REST API using Flask. This allowed the client’s customer support system to send new tickets to the API, which would return the predicted category in real time.
    • To ensure scalability, we containerized the Flask app with Docker and hosted it on AWS Elastic Beanstalk.

Challenges and Solutions

Building an AI system to handle real-world customer support tickets comes with its own set of challenges. Here’s how we addressed some of the main issues:

Handling Noisy Text Data

Challenge: Customer support messages often contain misspellings, slang, and informal language, making it harder for the model to classify them accurately.

Solution: We used text cleaning techniques such as removing special characters and correcting common spelling errors. Additionally, we employed word embeddings that could understand similar words in context (e.g., “delivery issue” and “delay”).

Dealing with Imbalanced Data

Challenge: Some categories (like "Payment Problem") had far fewer examples than others, which could bias the model.

Solution: We applied SMOTE (Synthetic Minority Over-sampling Technique) to balance the dataset by generating synthetic examples in underrepresented categories. This helped the model achieve more balanced classification accuracy.

Ensuring Model Interpretability

Challenge: The client needed to understand why certain tickets were categorized in specific ways.

Solution: We implemented SHAP (SHapley Additive exPlanations) values to explain the model’s decisions, allowing us to show which keywords influenced the model’s classification choices.

Results and Business Impact

After deploying the automated ticket classification system, the client achieved several measurable improvements:

  • Faster Ticket Processing: Average ticket processing time was reduced by 40%, allowing the support team to respond to customers faster.
  • Improved Customer Satisfaction: With faster response times, customer satisfaction scores increased by 15%.
  • Reduced Workload for Human Agents: By automating the initial sorting of tickets, the client was able to free up 30% of their support staff’s time, which they could then dedicate to more complex issues.
  • Scalability: The model handled high ticket volumes with ease, processing thousands of tickets daily without performance issues.