Breaking the Mold: Creating a Unique Dating App with Apache AGE and PostgreSQL
Tags: tutorial, postgres, opensource, database
Published: 2023-03-01 22:30:34

## The love in connections
With the growth of technology and cellphones, the use of dating apps has come to be one of the most popular ways of finding love. Tinder, for example, has over 10.7 million users, far more than any other dating app. Which raises us the question: how does it stores all this data? Does it use a graph database to store users data? If not, how can we create a graph database for a dating app? 

Well, today I'm going to show how we can do this! With the use of the glorious **Apache AGE**! A **beautiful** PostgreSQL extension that enables users to leverage a graph database on top of the existing relational database. It is **robust** and **fully featured**. Is AGE getting the attention here from all of our beloved database users? Oh, but I'll show you until the end of this tutorial that this graph database is the right **match** for you.

## Creating our users
Let's say that we created our dating app that features Apache AGE, Quirky Match. It encourages users to embrace their own quirks and find someone who appreciates them. Here is an advertisement for our app:

"Are you tired of swiping left and right, only to end up with a match who thinks a romantic dinner means a drive-thru? Look no further, because our Quirky Match is here to rescue you from mediocre dates and endless boredom.

With Quirky Match, you'll be matched with people who share your interests and quirks. Whether you're a fan of knitting or extreme sports, we'll find someone who appreciates your hobbies and can keep up with your level of enthusiasm.

And if you're tired of the same old ice-breakers, fear not. Our app features a "weird fact" section, where you can share your most bizarre and hilarious stories. Who knows, maybe your match is also a fan of collecting vintage rubber ducks or has a secret talent for juggling pineapples.

So what are you waiting for? Download Quirky Match today and let the fun (and weirdness) begin! Who knows, maybe you'll find your soul-mate and your next partner-in-crime all in one swipe."

With such a interesting ad, there where two people that downloaded our app: Alex and Sarah. Alex is a 27 year old graphic designer. He loves art, photography, traveling, indie music, and a weird fact about him is that he can hold up to 400 straws in his mouth for 20 seconds. Sarah is a 25 year old software engineer who likes hiking, board games, sci-fi movies and paints dungeons and dragons miniatures. A weird fact about her is that she has a collection of over 50 different types of hot-sauce, ranging from mildly spicy to painfully hot. 

We can add both of them to our graph:

```sql
-- Creating the graph
SELECT * FROM create_graph('QuirkyMatch');

-- Adding Alex and Sarah
SELECT * FROM cypher('QuirkyMatch', $$
    CREATE (:Person {
        name: 'Alex',
        age: 27,
        occupation: 'Graphic Designer',
        interests: ['Art', 'Photography', 'Traveling', 'Indies Music'],
        weird_fact: 'I can hold up to 400 straws in my mouth. LOL.'
    }), 
    (:Person {
        name: 'Sarah',
        age: 25,
        occupation: 'Software Engineer',
        interests: ['Hiking', 'Board Games', 'Sci-Fi Movies', 'Dungeons & Dragons', 'Painting', 'Art'],
        weird_fact: 'I collect hot sauces and I have over 50 different ones :)'
    })
$$) as (v agtype);
```

## Searching for someone special

Sarah notices that she can find people with a search engine in the app. So she searches for someone that is also into Art and is at least one year older than her.

```sql
SELECT * FROM cypher('QuirkyMatch', $$
    MATCH (v:Person), (user:Person)
    WHERE user.name = 'Sarah' AND v.age > (user.age + 1) AND 'Art' IN v.interests
    RETURN v
$$) as (potential_matches agtype);
```

And guess who was the first person she found there? Handsome Alex himself! She found funny the fact that he could hold those many straws in his mouth, and also looking at his pictures she found him quite handsome. So, Sarah swiped his profile to the right, making the app pop a few hearts on the screen.

```sql
SELECT * FROM cypher('QuirkyMatch', $$
    MATCH (a:Person), (b:Person)
    WHERE a.name = 'Sarah' AND b.name = 'Alex'
    CREATE (a)-[e:SWIPED_RIGHT]->(b)
    RETURN e
$$) as (swipped_right agtype);
```

Alex's phone makes a notification sound. He reads the pop-up message on his phone: "Sarah swiped you to the right! ;)". Looking at her profile, Alex got really interested in her, she found pretty cool that she collected hot sauces and painted miniatures. He then also swiped her profile to the right, making the app show "IT'S A MATCH!" at the screen.

```sql
ELECT * FROM cypher('QuirkyMatch', $$
    MATCH (a:Person), (b:Person)
    WHERE a.name = 'Alex' AND b.name = 'Sarah'
    CREATE (a)-[r:SWIPED_RIGHT]->(b), (a)-[m:MATCH]->(b)
    RETURN r, m
$$) as (swipped_right agtype, match agtype);
```

Sarah proceeds to sending him a message...

```sql
-- Create a Chat Vertex
SELECT * FROM cypher('QuirkyMatch', $$
    MATCH (a:Person), (b:Person)
    WHERE a.name = 'Sarah' AND b.name = 'Alex'
    CREATE (a)-[:IN_CHAT]->(v:Chat {messages: ['Can I be one of your straws?'], users: ['Alex', 'Sarah']})<-[:IN_CHAT]-(b)
    RETURN v
$$) as (chat agtype);
```

Alex and Sarah hit it off immediately after matching on the dating app. They went on several dates, going in various museums and painting miniatures together. They shared many laughs over their shared love of pizza and hot sauce, and bonded over their respective talents in art and engineering.

As they got to know each other better, Alex and Sarah realized that they had found something special in each other. They felt like they had finally found someone who truly understood them, quirks and all.

## The end.

In conclusion, Apache AGE provides an excellent solution for building a dating app that leverages the power of graph databases. By using AGE as a graph database extension for PostgreSQL, developers can create a dating app that can scale to millions of users while offering rich and dynamic relationship data. 

With AGE, developers can build a dating app that delivers a personalized and engaging experience for users. They can leverage the power of graph databases to model complex relationships between users, interests, and activities, and use this data to match users based on their shared interests and experiences.

So, if you are looking to build a dating app that is scalable, flexible, and dynamic, consider Apache AGE as your go-to graph database solution. Its powerful features and ease of use make it a great choice for developers who want to create a dating app that truly stands out in a crowded market.

Apache AGE website: https://age.apache.org/
Apache AGE GitHub repo: https://github.com/apache/age