1

I'm currently planning a social-media application - especially the backend. Basically I have all the social aspects for which I want to use SQL (PostgreSQL I guess) but I also have geolocations organized in lists (so many-to-one) which will propably make out the biggest ammount of data. I know that PostgreSQL has modules for GIS capabilities and my initial thought was to just use PostgreSQL for everything, just for the sake of simplicity and because performance of Geolocation searches should be around the same for both systems, if not even in favor of PostgreSQL. I can also use JSON Type in PostgreSQL so it basically has the most obvious advantages of MongoDB covered.

On the other hand I'm affraid of scalability as the geolocations are going to be the biggest chunk of data and the tables are propably going have heaps of rows.

So my thought now is to implement geolocations in MongoDB with its easy scalability, easy to use geolocation search and embedd e.g Comments/Likes for a geolocation directly into the document, which would make the geolocation reads/searches way easier but then again I had to combine this data with social data from SQL, e.g fetch all users that commented a geolocation and get their profile info from PostgreSQL and 'manually' combine it. Even though parts of this could be done on frontend saving me a lot of resources.

I'm not sure how good this idea performs and if I'm really doing myself a favor there.

3
  • What's your planned amount of "geolocations"? Commented Oct 9, 2016 at 21:22
  • Geolocations are entered by users, so basically unlimited or depending on the overall success. Commented Oct 10, 2016 at 2:17
  • 1
    I believe there is no right answer to your question. What I would do is to try to estimate the cost of migration from PG to MongoDB in case it would be necessary and compare it with an estimation of MongoDB operations cost (till the point of migration). As a developer, I'd prefer to use PostgreSQL and not to put any effort to a scalability that might not ever happen. Commented Oct 11, 2016 at 10:17

1 Answer 1

13

tldr: Use PostgreSQL.

Long answer:

You are trying to pre-optimize for a problem you don't even know if you will have. You don't know how many geolocations you will have, what the usage behaviors will be of your users and you probably don't even have any users yet.

I've used MongoDB before and migrated to PostgreSQL. There are many, many features and benefits to using a 'real' database for storing highly structured data. I suggest googling around for 'PostgreSQL vs X' articles, but the overall consensus that I've found is that PGSQL is extremely mature, reliable, performant and supported.

From my personal experience using Mongo then switching to PGSQL, I will never use Mongo again unless PGSQL (or another full-fledged SQL database) is completely falling over and I've spent months fixing it. Even then I'd take a hard look at other NoSQL databases too. PGSQL has so many amazing features and powerful tools that make it a joy to use.

For the seemingly few things you think you need Mongo for, PGSQL can do, and do just as well or better. It has native JSON types with indexes, geo support, full text indexing, etc. PGSQL has been around longer and has more support (useful for debugging, performance tuning, etc).

Regardless of which technologies you are thinking of using, you can't make any sort of informed decision if you don't:

  1. Test with large data sets

and

  1. Know your usage patterns and data volumes

So at this point I'd pick the more matured and powerful tool and setup monitoring for it. Watch the usage and performance of PGSQL, see how it holds up. Research best practices for PGSQL. Get to know it, learn it, dive in deep. When it comes to scaling individual services, each one is somewhat unique and will not fit a simple "Should I use X or Y?" question.

Good luck!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for this very detailed answer! I will definitely generate some data and test the performance.
Thanks! Would you mind upvoting or even selecting my response as a best answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.