Database is not necessarily needed it the application can do a bbox query and find nearest neighbor from the downloaded data locally. Perhaps you can find some suitable library which can perform the search of a nearest segment and consider then how to convert the OSM xml data into something that is understood by the library on-the-fly. Many digitising tools have an option “Snap to lines” which is probably internally doing first the spatial query you are interested in.