Autocomplete With Remote Data Sourced From Plain File Vs Database

I'm wondering what'd be faster. Let's say I've about 10K records which I need to search for autocomplete query. I believe I've two options-
  • Source the data from a plain file - either plain text or maybe json
  • Source data from database (MySQL)
My guess is that reading the text file would be much faster so that I can fetch all the records in one go and then perform search inside array to get relevant results for autocomplete query.

However, there's another thought that a properly indexed database can outperform approach #1.

I wish to know if anyone's faced similar situation and what was the optimum solution. How does the efficiency get affected when the number of records is say 50K or 100K?

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    FWIW, the server will run SSD; which should make file reading a lot faster. While, I also have the option of having memcache.
  • Kaustubh Katdare
    Kaustubh Katdare
    Tagging #-Link-Snipped-# and #-Link-Snipped-#
  • Prasad Ajinkya
    Prasad Ajinkya
    You need to factor in the speed of the clients as well. If its a relatively high end client, I'd go with json and do the heavy lifting at the client side 😛

    If its a low end client, then a mysql lookup it is.
  • Kaustubh Katdare
    Kaustubh Katdare
    Prasad Ajinkya
    You need to factor in the speed of the clients as well. If its a relatively high end client, I'd go with json and do the heavy lifting at the client side
    Everything's server side. What would be the use case to transport all the data from server to the client for processing? My thought is that I'd simply send an AJAX request to to server and let it do all the processing.

    With that setup - would you trust json to be speedier than mysql?
  • simplycoder
    simplycoder
    Nice question 😀

    I have not tried this practically, so I won't be clamming this but just my opinion,
    I think json would out perform mysql.

    Cache would play real important role here and I think it would outperform file read as well.

    Even if singleton pattern is correctly implemented for data access, it is likely, that connection handshake time would be higher than that of fetching the data, and if the plan is to hit the database every time a key is entered, it is very likely to be slower (due to db-server <-> app-server handshakes) than a file read.

    There is a third option which can be used, cache the records if they are to be retrieved as master.
    You can put a redis/memcache (or equivalent) and cache the data up, this should outperform both file reads as well as mysql in my opinion.

    One more option, I can think of is, cache the data (I am assuming master data) on server and then cache the data on browser (local storage), so this would help to reduce the trips if the user searches for the same data (This is optimizing thought, but felt to share).
  • Kaustubh Katdare
    Kaustubh Katdare
    simplycoder
    Even if singleton pattern is correctly implemented for data access, it is likely, that connection handshake time would be higher than that of fetching the data,
    That definitely is not the case. We inject delays and trigger the request only after 3 characters. However, if we ever use memcached or redis - we might bring it down to 1 keystroke.

    I'm not very sure if caching data on the client side is a good option - haven't really done this myself. I wonder if the method involves transporting entire data to client; and if that's the case we aren't likely to do that. Connection speeds in India aren't great. Plus, the data is likely to be used just once.

    Maybe server side caching is the key here. Gotta explore.

You are reading an archived discussion.

Related Posts

I completed my civil engineering , I have further decide to move in the field of construction management , and have entrepreneurial thoughts any suggestions by the elders and the...
Quote: No matter what you're in the mood to learn, there's a podcast out there to help you. The web's best educational podcasts can transform even the most boring commute...
A civil engineer by degree, Sameer Grover rode the tide of IT boom of the year 2000 and entered the software development industry. He started working as a programmer with...
hey guys, anyone have idea about how we can calculate apfc panel cable size for any load?
A satellite in space has limited shelf life. Once it runs out of fuel or breaks down, it gets effectively converted into space junk. National Aeronautics and Space Administration (NASA)...