 INIT_POLL_INTERVAL     = 3000
 MAX_POLL_INTERVAL      = 20000   # TODO: for testing -- for deploy make longer!
 POLL_DECAY_RATIO       = 1.4
+
+# Maximum allowed syncstring size -- we keep this manageable since we have to be
+# able to load the entire string within a few seconds from the database.
+MAX_STRING_LENGTH      = 5000000
 
 # We grab patches that are up to TIMESTAMP_OVERLAP old from db each time polling.
 # We are assuming a write to the database propogates to

                #dbg("nothing to do for #{string_id}")
                cb() # nothing to do
            else
                patch = diffsync.dmp.patch_make(string.last_sync, string.live)
                #dbg("patch for #{string_id} = #{misc.to_json(patch)}")
                timestamp = cass.now() - 0
                @db.update
                    table : 'syncstrings'
                    set   : {patch:@patch_to_string(patch)}
                    where : {string_id:string_id, timestamp:timestamp}
                    cb    : (err) =>
                        if err
                            cb(err)
                        else

        client = new diffsync.DiffSync(doc:@head)
        client.id = opts.session_id
        client.sync = (cb) =>
            if client.live.length > @max_length
                client.live = client.live.slice(0,@max_length)
            client.shadow    = client.live
            client.last_sync = client.live
            client.emit('sync')
