         @operations = require('./local/operations')
         @operations.setModel model
 
-    addFrontend: (frontend) ->
-        @remote.addFrontend frontend
+    addBackend: (backend) ->
+        @remote.addBackend backend
 
     resolve: (userId, cb) ->
         # First, look if already subscribed, therefore database is up to date:


class RemoteRouter
    constructor: () ->
        @frontends = []
        # cache :: { userId: { queue: [Function], result: ... } }
        @cache = {}

    addFrontend: (frontend) ->
        @frontends.push frontend

    resolve: (userId, cb) ->
        frontendIdx = 0
        go = () =>
            frontend = @frontends[frontendIdx]
            unless frontend
                return cb new errors.NotFound("Cannot resolve user")
            frontend.resolve userId, (error, result) ->
                if error
                    frontendIdx++
                    go()
                else
                    cb null, result

            else if !error || error.constructor is errors.NotFound
                # Otherwise, fan out to remote service
                @remote.resolve userId, cb
                # TODO: catch if remote backend found ourselves
            else
                cb error

